Android Service Listener For The Wakelock Screen
Solution 1:
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.
Solution 2:
You can create a BroadcastReceiver and register it with your application to listen for Intent.ACTION_SCREEN_OFF
, Intent.ACTION_SCREEN_ON
, and Intent.ACTION_USER_PRESENT
. Between SCREEN_OFF and USER_PRESENT, the phone is locked.
Solution 3:
There is no sanctioned way to replace the lock screen. See Is there a way to override the lock pattern screen?
The previous answer was to another question that got merged with this one:
I would look into ACTION_NEW_OUTGOING_CALL
, and also at this Android Developers blog post about receiver priority.
Post a Comment for "Android Service Listener For The Wakelock Screen"