0

Apparently, Android saves two values for the screen brightness: One for automatic adjustment and one for manual mode (at least on Nougat). How do I change the one for automatic adjustment?

If I change the screen brightness to 0 like this:

Settings.System.putInt(
    context.contentResolver,
    Settings.System.SCREEN_BRIGHTNESS, 
    0
)

then the one for manual mode is changed. While automatic adjustment is on, this code does not produce any visible change.

Here: https://stackoverflow.com/a/18312812 someone proposes to turn manual mode on first (SCREEN_BRIGHTNESS_MODE_MANUAL) but I want to keep automatic adjustment on.

Nemo
  • 728
  • 1
  • 4
  • 16
  • Why do you want to keep automatic adjustment on? Even if you somehow are able to set brightness in automatic mode, won't it get changed by sensor? – bhavya_karia Jun 14 '19 at 10:03
  • It will be adapted to the ambient brightness but overall, the screen brightness will stay higher/lower. And I want to keep automatic adjustment on because the users of my app probably want to keep it on (the change is supposed to be permanent) – Nemo Jun 15 '19 at 15:54

1 Answers1

1

If you set brightness mode to automatic. then you need to stop automatic brightness adjustment before sets brightness. this code worked for me:

    public static void stopAutoBrightness(Activity activity) {
          android.provider.Settings.System.putInt(activity.getContentResolver(),
                  android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE,
                  android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        }
Guokas
  • 750
  • 7
  • 23
  • I need to ON automatic brightness mode so I changed SCREEN_BRIGHTNESS_MODE_MANUAL to SCREEN_BRIGHTNESS_MODE_AUTOMATIC, and it works for me – Ahmad Sep 20 '22 at 06:39