Android的 - 如何prevent转动时音量或相机关键是pressed手机屏幕?

问题描述:

我有一个活动,显示了当手机屏幕进入睡眠/关机即变成黑色。 出于某种原因,在电话接通时,音量按钮或相机按钮是pressed。通过导通,我指的是屏幕唤醒或回来在黑屏状态。

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.

我已经使用dispatchKeyEvent(KeyEvent的事件)尝试和按钮都在活动的残疾人,但他们仍然清醒过来的电话。

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

您可以尝试重写的onkeydown(KeyEvent的)方法,并改变这些密钥会发生什么。不过,我不是太乐观,如果你正在运行的活动,这将是处于非活动状态时,显示屏关闭,并且也可能是手机硬连接到这些按钮上醒来。这可能是特定的设备。很难说。尝试了这一点,让我知道如何去,我currious

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