停止屏幕锁定时,电源按钮是pressed按钮、屏幕、电源、pressed

2023-09-06 19:29:02 作者:北遇长安

可能重复:   覆盖在电源键的Andr​​oid

有没有我可以停止屏幕任何可能的方式被锁定时,电源按钮是pressed。

Is there any possible way I can stop the screen being locked when the power button is pressed.

推荐答案

您不能停止屏幕,以获取锁(短按一下),但你可以得到的电源键的长按键preSS事件。

You can't stop screen to get lock(short click), But you can get the event of long keypress of Power button

 @Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
        //dostuff
        return true;
    }

    return super.dispatchKeyEvent(event);
}