using remote control for android TV application
Asked Answered
C

2

5

I'm developing an Android application for TV when I'm trying to test it in the real Android TV I can't navigate to any button or anything using the remote control buttons up, down, left, right.

I have searched about it and I found that I have to use (Enable D-pad Navigation ) but I don't know how to use this , I didn't find any code or tutorial for it My application is so simple. It makes dynamic layout beside each other and each layout has only one button and one recycle view.

Construct answered 30/8, 2017 at 14:58 Comment(1)
See: developer.android.com/training/keyboard-input/…Arleyne
K
5

By default Android implements basic D-Pad navigation inferred from the layout distribution. It works quite well if you use mostly lists or linear layouts.

The key difference is that the views are on the focused state instead of selected, so if you are using custom background i.e. for buttons it may look like it is not working while in fact it is.

You can try it out on an emulator using the cursor keys on the keyboard.

Alternatively or if the inferred navigation does not work you can define the nextFocusUp, Down, Left and Right per view.

It is all quite well explained on the official documentation: https://developer.android.com/training/tv/start/navigation.html

Kettledrum answered 31/8, 2017 at 7:44 Comment(0)
S
2

try this,

@Override
    public boolean onKeyDown(int keyCode, KeyEvent events) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_CENTER:

                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:

                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:

                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:

                break;
            case KeyEvent.KEYCODE_DPAD_UP:

                break;
            case KeyEvent.FLAG_KEEP_TOUCH_MODE:

                break;
        }
        return super.onKeyDown(keyCode, events);
    }

if in case call is not getInside above ,then try this:

  @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_CENTER:

                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:

                break;
            case KeyEvent.KEYCODE_DPAD_UP:

                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:

                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:

                break;
            case KeyEvent.FLAG_KEEP_TOUCH_MODE:

                break;
        }
        return super.dispatchKeyEvent(event);
    }
Sixfold answered 19/11, 2018 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.