Amazon Gift Cards

Sunday, May 24, 2009

Changing the Screen Brightness Programatically in Cupcake

Previously we had blogged about on how to change the screen brightness in android pre cupcake and on cupcake, the android team had added an official way to change the brightness without the hacks. Here is how to use it:

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 100.0f;
getWindow().setAttributes(lp);



References:
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#screenBrightness
http://groups.google.com/group/android-developers/browse_thread/thread/6de1cb84596a1c9b

Update History
   Jan 17, 2012 - Visual Update

6 comments:

Day 02: Flashlight - The journey with little green men said...

[...] Mendoza - Changing the Screen Brightness Programatically by bakhtiyor | Categories: Uncategorized | Enjoyed this article? Subscribe to the full RSS [...]

Tom Highland said...

How do you make it work in a widget since getWindow() isn't gonna work?

John B said...

I would like to know how to do this from a widget as well.

MorrisLiang said...

Well this only changes the current activity,not the entire system..Do you know how to change the brightness level for the cellphone?

MorrisLiang said...

OK,I figure it out myself.All you have to do is start up an activity,shows a button.When you click that button,write the system settings,which is "screen_brightness" or sth.Then you use the method in this post to actually change it.After doing these,you can leave your activty,and the brightness level remains.

Perry_ml said...

to MorrisLiang:
It does work on 1.5 virtual machine, but sadly it does not work on my Hero :( I am trying to figure out, any ideas would help me a lot. Thx.