While working on an application for Android TV devices I realized the buttons on the remotes varies between devices. For example; some remotes include a “mute” button while others don’t. The Android Studio d-pad simulator for the emulator also doesn’t include this button (and in some cases the buttons register as UNKNOWN). How am I supposed to verify my application works correctly for all buttons?
You can simulate remote control actions even if you don’t have a physical remote. You need to have the device successfully connected via ADB to continue. While your device is connected you can send simulated remote control input using the following command:
$ adb shell input keyevent [keycode]
Alternatively you can shell into the device using
adb shell and enter shorter commands:
input keyevent [keycode].
[keycode] represents the button you’re trying to simulate. The
KeyCodes are defined in
android.view.KeyEvent.java. See the KeyEvent.java documentation for the full list of available inputs.
Here’s a few examples of common inputs I used for Android TV:
# KEYCODE_DPAD_UP $ adb shell input keyevent 19 # KEYCODE_DPAD_DOWN $ adb shell input keyevent 20 # KEYCODE_DPAD_LEFT $ adb shell input keyevent 21 # KEYCODE_DPAD_RIGHT $ adb shell input keyevent 22 # KEYCODE_MEDIA_PLAY_PAUSE $ adb shell input keyevent 85 # KEYCODE_MEDIA_FAST_FORWARD $ adb shell input keyevent 90 # KEYCODE_MEDIA_REWIND $ adb shell input keyevent 89 # KEYCODE_MUTE $ adb shell input keyevent 91