Search code examples
androidandroid-appwidgetscreen-brightness

Create an Activity with no UI to do the brightness change in Appwidget


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?

Answer for this is Update Display Brightness on Android after changing it programmatically

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

How to create an Activity with no UI to do the brightness change in Appwidget??


Solution

  • I've had the same problem of changing screen brightness and i published the complete code of the solution here:

    https://stackoverflow.com/a/9848456/1204377

    I change it from a service, not widget, though. But still i believe you could easily adapt my code to work with a widget as well.