Detect power button long press

前端 未结 11 2296
轮回少年
轮回少年 2020-11-27 18:38

I\'ve been reading some posts here on Stackoverflow, and I didn\'t find a good solution, I\'m wondering if it\'s possible to detect when the user long press the power button

11条回答
  •  余生分开走
    2020-11-27 19:20

    Try this :

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
            Intent i = new Intent(this, ActivitySetupMenu.class);
            startActivity(i);
            return true;
        }
    
        return super.dispatchKeyEvent(event);
    }
    

提交回复
热议问题