有些場景須要程序自動點亮屏幕,解開屏幕鎖,以方便用戶即時操做,下面用代碼來實現這一功能:android
須要在AndroidManifest.xml添加權限:ui
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
flags參數說明:this
- PARTIAL_WAKE_LOCK: Screen off, keyboard light off
- SCREEN_DIM_WAKE_LOCK: screen dim, keyboard light off
- SCREEN_BRIGHT_WAKE_LOCK: screen bright, keyboard light off
- FULL_WAKE_LOCK: screen bright, keyboard bright
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 would be for notifications which are important for the user to see immediately.spa
ON_AFTER_RELEASE:f 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 cycling between wake lock conditions.code