Search code examples
androidandroid-5.0-lollipopbrightnessscreen-brightness

Change adaptive brightness level programmatically


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.


Solution

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