Topic:
When the android program is running, the background light remains awake, that is, no black screen.
First run the Code:
Note that you need to add permissions
<uses-permission android:name="android.permission.WAKE_LOCK"/>
/***** @ Author zhujianbin **/public class utils {Private Static wakelock Wl;/*** keep the screen awake (that is, the background light is not off) * @ Param on whether to wake up */public static void keepscreenon (context, Boolean on) {If (on) {powermanager PM = (powermanager) context. getsystemservice (context. power_service); WL = PM. newwakelock (powermanager. screen_bright_wake_lock | powermanager. on_after_release, "= keepscreenon ="); WL. acquire ();} else {WL. release (); WL = NULL ;}}}
Explanation:
Classes used
Powermanager
These two parameters are used: powermanager. screen_bright_wake_lock | powermanager. on_after_release
Below is the official Android API
Explanation:
He following flags are defined, with varying effects on system power.These flags are mutually exclusive-you may only specify one of them.
Flag Value |
CPU |
Screen |
Keyboard |
PARTIAL_WAKE_LOCK |
On * |
Off |
Off |
SCREEN_DIM_WAKE_LOCK |
On |
Dim |
Off |
SCREEN_BRIGHT_WAKE_LOCK |
On |
Bright |
Off |
FULL_WAKE_LOCK |
On |
Bright |
Bright |
It is generally necessary to keep the background normally when the program is running.
Screen_bright_wake_lock,
Screen_bright_wake_lock CPU: Wake up screen backlight: Wake up keyboard light: Off
The second parameter:
In addition, you can add two more flags, which affect behavior of the screen only.These flags have no effect when combined withPARTIAL_WAKE_LOCK
.
Flag Value |
Description |
ACQUIRE_CAUSES_WAKEUP |
Normal wake locks don't actually turn on the illumination. instead, they cause the illumination to remain on once it turns on (e.g. from user activity ). this flag will force the screen and/or keyboard to turn on immediately, when the wakelock is acquired. A typical use wocould be for communications which are important for the user to see immediately. |
ON_AFTER_RELEASE |
If this flag is set, the user activity timer will be reset when the wakelock is released, causing the illumination to remain on a bit longer. this can be used to reduce flicker if you are using ing between wake lock conditions. |