I want to listen to power key event. How can I do that?
Currently the code I am using is this:
@Override
public boolean onKeyDown(int keyCode, Ke
You should check in your override function onKeyDown
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_POWER) {
// Do something here...
return true;
}
return super.onKeyDown(keyCode, event);
}
and the same with onKeyLongPress if you using
Another way you would like to handle screen off, you can register BroadcastReceiver with action Intent.ACTION_SCREEN_OFF