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キーのために正常に動作上記code.Itsを使用して、電源ボタンイベントにアクセスしようとしているが、それが起こる電源/ロックButton.Whyのために働いていないのですアンドロイド
[Androidの電源ボタンに接続する方法は?](http://stackoverflow.com/questions/3703071/how-to-hook-into-the-power-button-in-android) – xAF
しかし、それも働いていない。 http://stackoverflow.com/questions/3703071/how-to-hook-into-the-power-button-in-android –