Android - 如何防止按下音量或相机键时手机屏幕打开?

发布于 2024-09-04 19:10:30 字数 154 浏览 2 评论 0原文

当手机屏幕进入睡眠/关闭状态(即变黑)时,我有一个活动会显示。 由于某种原因,按下音量按钮或相机按钮时手机会打开。我所说的打开是指屏幕唤醒或从黑屏状态返回。

我尝试过使用dispatchKeyEvent(KeyEvent event)并且按钮在活动上被禁用,但它们仍然唤醒手机。

I have an activity that shows up when the phone screen goes to sleep/turns off ie turns black.
For some reason, the phone turns on when the volume buttons or the camera buttons are pressed. By turns on, I mean the screen wakes up or comes back from the black screen state.

I've tried using dispatchKeyEvent(KeyEvent event) and the buttons are disabled on the activity, but they still wake up the phone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

风月客 2024-09-11 19:10:30

您可以尝试重写 onKeyDown(KeyEvent) 方法并更改这些键发生的情况。但是,我不太乐观,因为如果您正在运行一个活动,当显示屏关闭时它将处于非活动状态,而且也可能是手机硬连线以通过这些按钮唤醒。它可能是特定于设备的。很难说。尝试一下,让我知道效果如何,我很好奇

You could try overriding the onKeyDown(KeyEvent) method and change what happens for those keys. However, I'm not too optimistic as if you're running an activity, it will be in an inactive state when the display is off, and also it could be that the phone is hard wired to wake up on those buttons. It could be device specific. Hard to say. Try that out and let me know how it goes, I'm currious

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