Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long Press handing of D Pad center button via TV remote control

Tags:

android

amazon

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'

like image 289
Isha Dhawan Avatar asked Oct 17 '22 21:10

Isha Dhawan


1 Answers

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);
    }
}
like image 63
Isha Dhawan Avatar answered Oct 21 '22 03:10

Isha Dhawan