Change adaptive brightness level programmatically

允我心安 提交于 2019-12-07 16:22:24

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

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.

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