2013-03-18 81 views
0

在Android中設置autoBrightness非常簡單,不是嗎?立即生效的A​​ndroid 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); 

它不會自動適應,直到你鎖定屏幕,並再次將其鎖定。

+0

關於把'isAuto什麼? 0:1'在自己的()也許......? – TronicZomB 2013-03-18 12:07:49

+0

不太確定這是否會有所作爲。 – TronicZomB 2013-03-18 12:17:46

+0

isAuto?0:1是一個三元(布爾)表達式,它將完全相同或不帶圓括號,但它更清晰。我只是寫得很快,因爲這是一個問題 - 我想分享的答案,因爲它讓我瘋狂了幾周:-) – Twinone 2013-03-18 12:18:55

回答

0

我不知道爲什麼,但設置之前,再次將其設定爲0〜1部作品:

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