This article was reproduced in: http://blog.csdn.net/yudajun/article/details/7748760
Android Settings Branch Standby there are two ways
The first is simply achieved by setting the WindowManager property:
In the Activity Oncreat () method, set the
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_ SCREEN_ON);
The second implementation of PowerManager and Powermanager.wakelock using Android:
Add lock
Private voidAcquirewakelock () {if(WakeLock = =NULL) {LOGGER.D ("Acquiring Wake Lock"); PowerManager pm=(PowerManager) Getsystemservice (Context.power_service); WakeLock= Pm.newwakelock (Powermanager.screen_dim_wake_lock, This. GetClass (). Getcanonicalname ()); Wakelock.acquire (); } } //Release LockPrivate voidReleasewakelock () {if(WakeLock! =NULL&&Wakelock.isheld ()) {wakelock.release (); WakeLock=NULL; } }
The Acquirewakelock () method is called in the activity's onresume. The Releasewakelock () method is called in the activity's onpause. Use Activiy's life cycle to subtly make acquire () and release () pairs appear.
about int flags The effects of various types of locks on the CPU, screen, keyboard:
partial_wake_lock: Keep the CPU running, and the screen and keyboard lights may be off.
screen_dim_wake_lock: Keep the CPU running, allow the screen to be displayed but may be gray, allow to turn off the keyboard light
screen_bright_wake_lock: Keeps the CPU running, allowing the screen to be highlighted, allowing the keyboard light to be turned off
full_wake_lock: Keep the CPU running, keep the screen highlighted, and the keyboard lights remain bright
Don't forget it at last!
The operation to be powered requires that the app has permission to set power management in Androidmanifest.xml.
<uses-permission android:name= "Android.permission.WAKE_LOCK"/> You may also need <uses-permission android:name= " Android.permission.DEVICE_POWER "/>
Turn: Android settings screen is not standby