I'm having trouble trying to set screen brightness. To do so I use the following code:
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
where brightness
is a value between 0 and 255.
The problem is that in some device it works (Htc One, Nexus 5,...), in others dont! For example, if I use this function to set screen brightness in a Samsung device the screen doesnt get brighter or dimmer, altough if i go into "Notification Panel" (sliding down from the top of the screen) i can see the brightness level has changed.
Does anyone know a way to set brightness that works with all Android devices? And does anyone know why it works in some devices, but in other dont?
UPDATE 1:
This method is used in a BroadcastReceiver, so no Activities are there!
You can override the brightness for the current window, instead of changing the brightness settings.
WindowManager.LayoutParams lp = getWindow().getAttributes();
if (overrideBrightness)
lp.screenBrightness = BRIGHTNESS_OVERRIDE_FULL;
else
lp.screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
getWindow().setAttributes(lp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With