【发布时间】:2016-05-11 09:08:49
【问题描述】:
i=0;
public boolean onKeyDown(int keyCode, KeyEvent event) {
System.out.println("In Key Down Method." + event.getKeyCode());
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
i++;
System.out.println("Power button pressed.");
if (i == 2) {
System.out.println("Power button pressed continuoulsy 3 times.");
Toast.makeText(MainActivity.this, "Power button pressed " + i + " times.", Toast.LENGTH_SHORT).show();
} else {
System.out.println("Power button pressed continuoulsy " + i + " times.");
Toast.makeText(MainActivity.this, "Power button pressed " + i + " times.", Toast.LENGTH_SHORT).show();
}
}
return super.onKeyDown(keyCode, event);
}
我正在尝试使用上述代码访问电源按钮事件。它适用于 Volume_Up 和 Volume_Down 键,但不适用于电源/锁定按钮。为什么会发生这种情况? 建议一些示例或代码。
【问题讨论】:
标签: android android-event