Android Write app can actually adjust the screen brightness, check the data found Windowmanager.layoutparams This class contains the parameters to adjust the brightness:
Windowmanager.layoutparams LP = GetWindow (). GetAttributes ();
lp.screenbrightness = 0.1f;
Where the parameter screenbrightness is the setting screen brightness of the 0.0f screen is the darkest ,1.0f screen Brightest
On this basis I added a SeekBar to adjust the screen brightness,
The code reference is as follows:
Also in the callback function must have the following sentence GetWindow (). SetAttributes (LP); Otherwise, it does not work. I set the value directly in the OnCreate () function at the beginning , without which it can be directly adjusted, but it does not work if the callback function is not added .
Public classBlightactivityextendsActivity {intmax_brightness = 100; SeekBar Bseekbar=NULL;floatFbrightness = 0.0f; Windowmanager.layoutparams LP=NULL; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Bseekbar=(SeekBar) Findviewbyid (R.id.blightbar); Bseekbar.setonseekbarchangelistener (Seeklistener); Bseekbar.setmax (max_brightness); LP=GetWindow (). GetAttributes ();//lp.screenbrightness = 0.1f;} onseekbarchangelistener Seeklistener=NewOnseekbarchangelistener () { Public voidOnstoptrackingtouch (SeekBar SeekBar) {//TODO auto-generated Method Stub} Public voidOnstarttrackingtouch (SeekBar SeekBar) {//TODO auto-generated Method Stub} Public voidOnprogresschanged (SeekBar SeekBar,intProgress,BooleanFromuser) {//TODO auto-generated Method StubFbrightness = (float) Progress/(float) max_brightness;lp.screenbrightness=fbrightness;//this should be added, otherwise the screen brightness does not functionGetWindow (). SetAttributes (LP); System.out.println ("Fy_" +fbrightness);}};}
View Code
Here's how to keep the background light constant:
The first is to get permission:
<uses-permission android:name= "Android.permission.WAKE_LOCK" ></uses-permission>
Here is the control code instance
Public classTestextendsactivity{PowerManager PowerManager=NULL; WakeLock WakeLock=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); This. Setcontentview (R.layout.main); This. PowerManager = (PowerManager) This. Getsystemservice (Context.power_service); This. WakeLock = This. Powermanager.newwakelock (Powermanager.full_wake_lock, "My LOCK"); This. Wakelock.acquire (); } @Overrideprotected voidOnresume () {Super. Onresume (); //re-fetch This. Wakelock.acquire (); } @Overrideprotected voidOnPause () {Super. OnPause (); //release Wakelock When the activity is destroyed This. Wakelock.release (); } }
View Code
Transferred from: http://blog.csdn.net/zqiang_55/article/details/8043661#comments
Android_ Adjust the screen brightness (background light) and keep the background light on the way (turn)