Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Display Brightness on Android after changing it programmatically

I'm trying to update the display brightness from a widget but i have some problems.

To change brightness level, i use:

Settings.System.putInt(context.getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS, 200);

This modifies the display setting (in fact in Display->Brightness the level is correct) but the effective brightness of display is not changed. If i lock the screen and unlock, the brightness finally changes to the value i set.

I assume this is a Settings Update issue, so how can the display settings be immediatly updated after settings change?

I read that WindowManager.LayoutParams lp = getWindow().getAttributes(); should be used but I am working in a App Widget so getWindow() cannot be called.

like image 295
Mariux Avatar asked Dec 06 '10 12:12

Mariux


2 Answers

I had a similar issue and just created an Activity with no UI to do the brightness change, used an intent to run it from the App Widget.

like image 74
GeekYouUp Avatar answered Nov 10 '22 14:11

GeekYouUp


First, the value to modify in LayoutParams is screenBrightness. You'll then have to do a window.setAttributes to apply it. As GeekYouUp said, you can make a dummy activity to get your Window object.

like image 32
Valentin Rocher Avatar answered Nov 10 '22 14:11

Valentin Rocher