1

I use this code to reduce screen brightness but it only work in android 4.4--. When I test in android 5++ then it work when Activity open, after I finish/close Activity then the screen brightness return default setting before. How can I keep screen brightness setting in android 5.0++

    cResolver = getContentResolver();
    window = getWindow();
    android.provider.Settings.System.putInt(cResolver,
            android.provider.Settings.System.SCREEN_BRIGHTNESS,75);
    WindowManager.LayoutParams layoutpars = window.getAttributes();
    layoutpars.screenBrightness = 75 / (float) 255;
    window.setAttributes(layoutpars);
Ken Kem
  • 635
  • 1
  • 6
  • 13

1 Answers1

0

Is adaptive brightness enabled on the device? This will mean the brightness level falls within a user-defined range, rather than using the single value you provide. Try disabling it before running the code you posted, and see if it makes a difference.

Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL)

Also, see this question for help with changing the value when adaptive mode is enabled.

Community
  • 1
  • 1
idunno
  • 713
  • 3
  • 10
  • 25