1

我的应用程序通过以下方式保存用户原始亮度:

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);
}

对男性有用吗?谢谢

4

1 回答 1

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" />
于 2012-11-03T19:53:12.673 回答