Change adaptive brightness level programmatically

 ̄綄美尐妖づ 提交于 2019-12-08 06:01:05

问题


How can I change the adaptive brightness level programmatically, on Android Lollipop?

I know how to change the manual brightness level, and to toggle on or off the adaptive brightness. It is done like that: Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, newLevel);

However, with adaptive brightness is enabled, the OS combines it with another brightness level which is different than the manual one.

Is there a way to do this?

Target/min/max SDK is 21.


回答1:


Don't know why but there is a hidden constant SCREEN_AUTO_BRIGHTNESS_ADJ in Android API to adjust adaptive brightness. But you can pass "screen_auto_brightness_adj" string value instead like I did.

Adaptive brightness adjustment is stored as float value in range [-1;1]. If you use brightness value in range [0;255], you can convert it to proper value as shown below.

float value = (((float)brightness*2)/255) - 1.0f;
Settings.System.putFloat(contentResolver, "screen_auto_brightness_adj", value);



回答2:


If your app targetSdkVersion is 23+, Settings.System.putFloat(contentResolver, "screen_auto_brightness_adj", value) won't work as Android disables you to modify any "hidden" settings.

Read frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\SettingsProvider.java warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk() for details.



来源:https://stackoverflow.com/questions/29349153/change-adaptive-brightness-level-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!