用于唤醒锁屏幕的 Android 服务侦听器
大家好,
我正在开发一个紧急呼叫应用程序。我想要的是,当有人使用这个特定代码时,手机将解锁,然后只有我的应用程序会运行。我只是想我需要一个接收器,只是想知道我是否必须为我的应用程序创建自己的主屏幕和锁定屏幕。有什么想法吗?
提前非常感谢:)
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 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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建一个 BroadcastReceiver 并将其注册到您的应用程序中以侦听
Intent.ACTION_SCREEN_OFF
、Intent.ACTION_SCREEN_ON
和Intent.ACTION_USER_PRESENT
。在 SCREEN_OFF 和 USER_PRESENT 之间,手机被锁定。You can create a BroadcastReceiver and register it with your application to listen for
Intent.ACTION_SCREEN_OFF
,Intent.ACTION_SCREEN_ON
, andIntent.ACTION_USER_PRESENT
. Between SCREEN_OFF and USER_PRESENT, the phone is locked.仅执行 SCREEN_OFF 和 USER_PRESENT 有一些注意事项
1) 如果屏幕自行超时,屏幕关闭后手机不会立即锁定,会有几秒钟的延迟
2) 如果屏幕因其他原因(电话)关闭,则可能根本无法锁定。
3) 你必须一直监控它们,如果你在手机锁定时启动,你不会知道
你可以使用
KeyguardManager
http://developer.android.com/reference/android/app/KeyguardManager.html 并检查inKeyguardRestrictedInputMode()
另一种选择是使用 PowerManager http:// developer.android.com/reference/android/os/PowerManager.html 并检查
isScreenOn()
如果您实际上只关心屏幕状态而不是键盘状态。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 checkinKeyguardRestrictedInputMode()
Another option would be to use the
PowerManager
http://developer.android.com/reference/android/os/PowerManager.html and checkisScreenOn()
if you actually just care about screen state and not keyguard state.没有经过批准的方法可以更换锁屏。请参阅 是否有办法覆盖锁定图案屏幕?
之前的答案是与此问题合并的另一个问题:
我会调查ACTION_NEW_OUTGOING_CALL
,以及 这篇关于接收器优先级的 Android 开发者博客文章。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 intoACTION_NEW_OUTGOING_CALL
, and also at this Android Developers blog post about receiver priority.