2010-08-16 52 views
3

我在我的搜索中看到了2種方法,這兩種方法我都遇到了麻煩。什麼是調暗屏幕的正確方法?

方法1)

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100); 

方法2)

IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware")); 
hardware.setScreenBacklight(.5); 

哪個這些方法是正確的?或者我應該使用另一個?

感謝

+0

這是什麼錯? – 2010-08-17 23:09:30

回答

5

我用下面的代碼做同樣的

WindowManager.LayoutParams WMLP = getWindow().getAttributes(); 
WMLP.screenBrightness = 0.15F; 
getWindow().setAttributes(WMLP); 

使用上述代碼的優點是,這會影響屏幕亮度僅在調用它的活動。所以當我移動到其他活動(或)退出應用程序時,手機的默認亮度(由用戶設置)被恢復。

編輯: 我忘了提及的是,screenBrightness屬性的範圍爲0.0 - 1.0

-1

android.provider.Settings.System.putInt(getContentResolver(), Settings.System.DIM_SCREEN,時間);時間以毫秒爲單位。但此Settings.System.DIM_SCREEN被刪除。

相關問題