0

在 Android 中设置 autoBrightness 很容易,不是吗?

Settings.System.putInt(resolver,
        Settings.System.SCREEN_BRIGHTNESS_MODE, 0); // 0 is manual, 1 is auto

但是,如果您要切换:

boolean isAuto = Settings.System.getInt(resolver, 
        Settings.System.SCREEN_BRIGHTNESS_MODE) == 1;
Settings.System.putInt(resolver,
        Settings.System.SCREEN_BRIGHTNESS_MODE, isAuto ? 0 : 1);

在您锁定屏幕并再次锁定之前,它不会自动适应。

4

1 回答 1

0

我不知道为什么,但是在将其设置为 1 之前再次将其设置为 0 有效:

boolean isAuto = Settings.System.getInt(resolver, 
    Settings.System.SCREEN_BRIGHTNESS_MODE) == 1;
if (isAuto) {
    Settings.System.putInt(resolver,
        Settings.System.SCREEN_BRIGHTNESS_MODE, 0); // set to 0 again, even if it is already 0
    Settings.System.putInt(resolver,
        Settings.System.SCREEN_BRIGHTNESS_MODE, 1); // now it auto-adapts
} else {
    Settings.System.putInt(resolver,
         Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
}
于 2013-03-18T12:05:39.703 回答