Android - 如何防止按下音量或相机键时手机屏幕打开?
当手机屏幕进入睡眠/关闭状态(即变黑)时,我有一个活动会显示。 由于某种原因,按下音量按钮或相机按钮时手机会打开。我所说的打开是指屏幕唤醒或从黑屏状态返回。
我尝试过使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试重写 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