Keep the screen on when running the program.
Powermanager. wakelock must be released and enabled in pairs.
The impact of various lock types on the CPU, screen, and keyboard:
Partial_wake_lock: to keep the CPU running, the screen and keyboard lights can be turned off.
Screen_dim_wake_lock: to keep the CPU running and display on the screen, but it can be dimmed to allow the keyboard light to turn off.
Screen_bright_wake_lock: allows you to keep the CPU running, highlight the screen, and turn off the keyboard light.
Full_wake_lock: keeps the CPU running, and keeps the screen and keyboard lights highlighted.
Acquire_causes_wakeup: the screen is highlighted immediately after the lock is obtained. It is typically used in notification so that users can view the lock immediately.
On_after_release: After the release lock (release (), the screen of the mobile phone will continue to shine for a while.
Package COM. example. sensortest; import android. OS. bundle; import android. OS. powermanager; import android. app. activity; import android. content. context; public class mainactivity2 extends activity {private powermanager. wakelock = NULL; @ overrideprotected void oncreate (bundle savedinstancestate) {setcontentview (R. layout. activity_main2); // todo auto-generated method stubsuper. oncreate (savedinstances Tate) ;}@ overridepublic void onresume () {acquirewakelock (this); super. onresume () ;}@ overridepublic void onpause () {releasewakelock (); super. onpause () ;}// obtain the lock public void acquirewakelock (context) {If (wakelock = NULL) {powermanager = (powermanager) (context. getsystemservice (context. power_service); wakelock = powermanager. newwakelock (powermanager. screen_dim_wake_lock, "my tag"); wake Lock. Acquire () ;}}// release the public void releasewakelock () {If (wakelock! = NULL & wakelock. isheld () {wakelock. Release (); wakelock = NULL ;}}}