changing screen brightness programmatically in android

Sri Sri picture Sri Sri · Sep 17, 2010 · Viewed 61.9k times · Source

I want to change the screen brightness programmatically in android. At the moment I use this code:

WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness=1.0f;
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);

But this sample code works on cupcake, not on latest versions. I am using the latest version of SDK.. What is the preferred solution for newer Android Versions?

Answer

Tor-Morten picture Tor-Morten · Oct 5, 2010

This is possible to do by using:

WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1F;
getWindow().setAttributes(layout);

See also: http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#screenBrightness