0

Is there a way to switch to an HDMI input programmatically on Android TV? I.e. a Smart TV, not a separate box.

What I was trying is to send a key event like this:

# `someButton` is a button on the `activity_main.xml`

val inputConnection = BaseInputConnection(someButton.rootView, true);
inputConnection.sendKeyEvent(
    KeyEvent(
        KeyEvent.ACTION_DOWN,
        KeyEvent.KEYCODE_TV_INPUT_HDMI_4,
    )
)
inputConnection.sendKeyEvent(
    KeyEvent(
        KeyEvent.ACTION_UP,
        KeyEvent.KEYCODE_TV_INPUT_HDMI_4,
    )
)

Running this has no effect. Other keys like KEYCODE_BACK work as expected, so I assume this functionality can only send key events to the app, not the host device itself.

For reference, running the following via adb from my computer works:

adb connect MY_TV
adb shell input keyevent 246

But of course I don't have permissions to run Runtime.getRuntime().exec(arrayOf("/bin/sh", "-c", "input keyevent 246")) from within the app.

For reference, what I tried so far:

denoyse
  • 1
  • 3

0 Answers0