I am working on TV application using Amazon Fire Stick TV. I need to handle long press event for the Dpad center button via TV remote control.
For the Dpad center button, only I receive a call to onKeyDown()
multiple times if I long press the DPad center button.
I do not receive any call to OnKeyUp()
methods and onLongKeyPress()
methods of the Activity while trying to long press the DPad center button. Is this a bug?
Compile SDK version is '23'
I solved it by handling KEYCODE_DPAD_CENTER
keyevent in the dispatchKeyEvent(KeyEvent event)
like this:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
Log.d(TAG,"Down time is" + event.getDownTime()+"with action:" + event.getAction()+ "with repeat count"+ event.getRepeatCount()+"with long press"+ event.isLongPress());
if (action == KeyEvent.ACTION_DOWN && event.isLongPress()) {
Log.d(TAG,"LOng pres Down time is" + event.getDownTime());
Log.d(TAG, "Inside long press of Dpad center event");
onCenter();
return true;
}
default:
return super.dispatchKeyEvent(event);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With