我的应用通过以下方式保存用户原始亮度:
originalBrightness = Settings.System.SCREEN_BRIGHTNESS;
然后在程序运行时更改它。
originalBrightness是私有全局字符串。现在我想要做的是当用户点击“主页”或当应用程序暂停原始屏幕需要再次设置时,我试图这样做,但应用程序粉碎了:
public void onPause() {
super.onPause();
int brightness = Integer.getInteger(originalBrightness);
setBrightness(brightness);
}
private void setBrightness(int brightness) {
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = brightness / 100.0f;
getWindow().setAttributes(layoutParams);
}
男性有工作吗?感谢
答案 0 :(得分:1)
尝试使用Settings.System.SCREEN_BRIGHTNESS
将系统默认亮度设置为:
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,brightness /100.0f); // 0-255
并在清单中添加这些权限:
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />