开发者

Android Service Listener for the wakelock screen

开发者 https://www.devze.com 2023-03-02 09:30 出处:网络
Hii all, Im developing an emergency calling application. What i want is when some 开发者_如何学JAVAperson uses this specific code the phone will unlock and then only my application would be running.

Hii all,

Im developing an emergency calling application. What i want is when some 开发者_如何学JAVAperson uses this specific code the phone will unlock and then only my application would be running. Im juz thinking i need a reciever for it and just wondering wether i will have to create my own Home screen and a lock screen for my application. any ideas on this please???

many thanks in advance :)


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号