用于唤醒锁屏幕的 Android 服务侦听器

发布于 2024-11-05 01:54:52 字数 143 浏览 6 评论 0原文

大家好,

我正在开发一个紧急呼叫应用程序。我想要的是,当有人使用这个特定代码时,手机将解锁,然后只有我的应用程序会运行。我只是想我需要一个接收器,只是想知道我是否必须为我的应用程序创建自己的主屏幕和锁定屏幕。有什么想法吗?

提前非常感谢:)

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光磨忆 2024-11-12 01:54:53

您可以创建一个 BroadcastReceiver 并将其注册到您的应用程序中以侦听 Intent.ACTION_SCREEN_OFFIntent.ACTION_SCREEN_ONIntent.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, and Intent.ACTION_USER_PRESENT. Between SCREEN_OFF and USER_PRESENT, the phone is locked.

丿*梦醉红颜 2024-11-12 01:54:53

仅执行 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 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.

我不会写诗 2024-11-12 01:54:53

没有经过批准的方法可以更换锁屏。请参阅 是否有办法覆盖锁定图案屏幕?

之前的答案是与此问题合并的另一个问题:

我会调查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 into ACTION_NEW_OUTGOING_CALL, and also at this Android Developers blog post about receiver priority.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文