我在android中检测到电源按钮按下事件。在正常应用程序中,按下电源按钮后,设备屏幕将关闭,但是在创建系统证书应用程序时,设备屏幕将保持打开状态。
答案 0 :(得分:0)
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
// do what you want with the power button
return true;
}
return super.onKeyDown(keyCode, event);
}
或尝试
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
// do what you want with the power button
}
return super.dispatchKeyEvent(event);
}