Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android short screen brightness code!

Anyone who knows why this code ain't lowering the backlight of my application?

Context context = this;

    Settings.System.putInt(context.getContentResolver(),
    Settings.System.SCREEN_BRIGHTNESS, 255);
like image 298
Blareprefix Avatar asked May 27 '11 23:05

Blareprefix


1 Answers

Applications are no longer allowed to modify the global brightness. Don't use the tricks people have tried to come up with at various points, these use private APIs and will break in various ways across different devices (and are considered security holes that have been closed on more recent versions of the platform).

The official API to set the brightness is with WindowManager.LayoutParams.screenBrightness, which lets you set the brightness for your own app's window. The platform will automatically take care of changing the brightness as the user moves in and out of your app.

Use this to change it:

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = <some value between 0 and 1>;
getWindow().setAttributes(lp);
like image 199
hackbod Avatar answered Oct 05 '22 22:10

hackbod