Android Service Listener for the wakelock screen

前端 未结 3 2106
予麋鹿
予麋鹿 2020-12-12 07:53

Hii all,

Im developing an emergency calling application. What i want is when some person uses this specific code the phone will unlock and then only my application w

3条回答
  •  渐次进展
    2020-12-12 08:44

    There's some caveats in just doing SCREEN_OFF and USER_PRESENT 1) Phone isn't locked right after screen off if the screen timed out by itself, there's a few second delay 2) If screen goes off for other reasons (phone call) it might not be locked at all. 3) You'd have to be monitoring them the whole time, if you're started when the phone is locked you wouldn't know

    You can use the KeyguardManager http://developer.android.com/reference/android/app/KeyguardManager.html and check inKeyguardRestrictedInputMode()

    Another option would be to use the PowerManager http://developer.android.com/reference/android/os/PowerManager.html and check isScreenOn() if you actually just care about screen state and not keyguard state.

提交回复
热议问题