Search This thread

Double_A_92

Member
May 15, 2021
21
22
LG Optimus 2x
Huawei P20 Lite
Remapping Android TV remote buttons
In this guide I will explain a way to remap to the shortcut buttons on the remotes of Android TV devices which cannot simply be remapped by e.g. Button Mapper.
I will use the Walmart Onn Box as example for this guide, but it should also work for devices like the Xiaomi Mi Box.

The general idea is to install an Android automation app which analyzes the system logs of you device and starts your desired apps when it sees the button press log messages.


Enabling ADB
To install the automation app and give it permissions it needs, you must enable developper mode on your Android TV device and connect to it from your computer.
Those two turorials should explain you how to do it:

Easy way to control your Android TV device
Since it is very cumbersome or impossible to do everything with the remote control I recommend to use ScrCpy.
This allows you to easily control your device from your computer using mouse and keyboard.

After installation you can connect to your device with adb and enter 'scrcpy' in your console. You should instantly see the screen of your TV on your computer.


Installing 'Automate'
The app I recommend for the automation is called 'Automate'. It is free, but sadly can't be directly installed from the app store on Android TV (because of compatibility).

To avoid this limitation you can download the APK from e.g. Apkmirror and install it manually via ADB.
adb install .\path\to\the\downloaded\apk\Automate_v1.32.6.apk

While you are at it you can also give the app some privileges which it needs later to read the system logs and to start the apps.

adb shell pm grant com.llamalab.automate android.permission.SYSTEM_ALERT_WINDOW
adb shell pm grant com.llamalab.automate android.permission.READ_LOGS

To start Automate you need a launcher that can see sideloaded apps. I recommend the X-plore File Manager since it's also a good file manager and can be easily installed from the app store.

( There are also other alternatives like 'Tasker' instead of 'Automate', but since that is not free and activation doesn't work properly on a sideloaded app I can't recommend that. )


Configuring 'Automate'
After starting Automate you can create a new 'flow'. The goal of that flow is to monitor the system logs, and start your desired apps everytime it sees a button press message.

That can be done mainly with a 'Log await' node that contains following configuration:
Tag: WindowManager
Message: .*interceptKeyTq keycode=(\d+).*
Priority: Debug
Logged message (array): keycode

You can then use "Expression true?" nodes to check for the found value in keycode (e.g. for the Live TV button) ...
Formula: =keycode[1] = "172"
... and start your desired app with "App start" nodes.
Package: com.google.android.tv

An example of a full flow can be found here: 📺🎛️ Remap Onn. Android TV remote buttons


Conclusion
After setting all this up the apps should start when you press the buttons.
However the original app (or its installation view) also starts before it, so if you press the back button you will return to that app instead of the previously running app. To avoid that just use the home button instead.

The Automate app will not automatically start if you reboot your Android TV device. If you want that you can activate that in the settings: 'Run on system startup'. But make sure that everything works perfectly before you do that!

If you get stuck in a loop where you can't use other apps and also can't open and configure Automate anymore, you can use this command via ADB to disable all flows:
adb shell am broadcast -a com.llamalab.automate.intent.action.STOP_FLOW -n com.llamalab.automate/.StartServiceReceiver
 

Attachments

  • Example Flow for Button Remapping.png
    Example Flow for Button Remapping.png
    611.2 KB · Views: 478
Last edited:

stapreedi

New member
May 13, 2022
3
1
Thanks for your guide. Now my Xiaomi Stick 4K remotes Netflix, Prime Video and Patchwall buttons are changed to open other apps.

Can you make Automate flow work like Button Mapper having also double click and long press open different apps.
 
  • Like
Reactions: Double_A_92

omdhar

Senior Member
Sep 29, 2012
232
60
Dimapur
Thanks for Idea. I have acer remote with netflix, youtube, primevideo and tiki live button. How to find keycode for these button in my acer remote because given keycode don't works
 

Double_A_92

Member
May 15, 2021
21
22
LG Optimus 2x
Huawei P20 Lite
Thanks for Idea. I have acer remote with netflix, youtube, primevideo and tiki live button. How to find keycode for these button in my acer remote because given keycode don't works
Connect the output of the "Log await" with the "Toast show" node, and the output of that back into the "Log await". That will create a little message popup with the keycode everytime you press a button.
 
  • Like
Reactions: omdhar

omdhar

Senior Member
Sep 29, 2012
232
60
Dimapur
Connect the output of the "Log await" with the "Toast show" node, and the output of that back into the "Log await". That will create a little message popup with the keycode everytime you press a button.
Thanks. It will be great if you could share flow example to generate keycode in message popup. It will also help many other here too.
 
Last edited:

stapreedi

New member
May 13, 2022
3
1
Thanks. It will be great if you could share flow example to generate keycode in message popup. It will also help many other here too.

Download this file Remap Onn. Android TV remote buttons and do what Double_A_92 told. Use your tablet or phone to modify flow file because its easier. When you modify flow file on your tablet or phone then you have to use example Aida64 for app package names on your tv. Use Send files to TV for what app name says. You can do it from Automate apps share icon.
 
Last edited:

harel013

Senior Member
May 16, 2013
71
9
Hey, thanks for the detailed guide! :) i did everything (i think 😄)but when i hit start its stuck on the “Log await” i used your shared flow cause i got the same box.
Any ideas?
 

Attachments

  • 80A606AE-ED4C-4463-BD72-0DA94EAF9B25.jpeg
    80A606AE-ED4C-4463-BD72-0DA94EAF9B25.jpeg
    5.8 MB · Views: 58

Double_A_92

Member
May 15, 2021
21
22
LG Optimus 2x
Huawei P20 Lite
Hey, thanks for the detailed guide! :) i did everything (i think 😄)but when i hit start its stuck on the “Log await” i used your shared flow cause i got the same box.
Any ideas?
Hmm weird. Try deleting the flow and download it again so you have a fresh copy.

Also make sure to configure which apps you want to start. In my shared flow they are just random apps that I had installed. Maybe that causes problems if they aren't actually installed on the system.
 

Double_A_92

Member
May 15, 2021
21
22
LG Optimus 2x
Huawei P20 Lite
what is different between this way and others way like "Button Mapper" or tvQuickActions?
This is for devices where the vendor buttons are not even registered as button presses by the system. So if you tried to use ButtonMapper or other apps, it wound't let you select the button and instead always open the app written on the button.

But yeah, if ButtonMapper works for your device that's obviously a much better way of doing it.
 
  • Like
Reactions: oldman20
This is for devices where the vendor buttons are not even registered as button presses by the system. So if you tried to use ButtonMapper or other apps, it wound't let you select the button and instead always open the app written on the button.

But yeah, if ButtonMapper works for your device that's obviously a much better way of doing it.
thank, it got it!
btw, can i ask this?
How to check succeeded in transforming tv box into an Android TV ? or just download app from Google Play without issue?
 

NarkosNakan

New member
Jun 18, 2022
4
0
I have the entire thing written out and plugged in, the only issue im having now is "Syntax error in regexp pattern near index1" i cant figure out through google what im doing wrong.
 

NarkosNakan

New member
Jun 18, 2022
4
0
The last problem im having is finding key codes, i don't understand how we find those for the app.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    what is different between this way and others way like "Button Mapper" or tvQuickActions?
    This is for devices where the vendor buttons are not even registered as button presses by the system. So if you tried to use ButtonMapper or other apps, it wound't let you select the button and instead always open the app written on the button.

    But yeah, if ButtonMapper works for your device that's obviously a much better way of doing it.
    1
    I have the entire thing written out and plugged in, the only issue im having now is "Syntax error in regexp pattern near index1" i cant figure out through google what im doing wrong.
    Make sure you really wrote
    .*interceptKeyTq keycode=(\d+).*
    With all the dots and asterisks....
    1
    The last problem im having is finding key codes, i don't understand how we find those for the app.
    Connect the output of the "Log await" with the "Toast show" node, and the output of that back into the "Log await". That will create a little message popup with the keycode everytime you press a button.
  • 5
    Remapping Android TV remote buttons
    In this guide I will explain a way to remap to the shortcut buttons on the remotes of Android TV devices which cannot simply be remapped by e.g. Button Mapper.
    I will use the Walmart Onn Box as example for this guide, but it should also work for devices like the Xiaomi Mi Box.

    The general idea is to install an Android automation app which analyzes the system logs of you device and starts your desired apps when it sees the button press log messages.


    Enabling ADB
    To install the automation app and give it permissions it needs, you must enable developper mode on your Android TV device and connect to it from your computer.
    Those two turorials should explain you how to do it:

    Easy way to control your Android TV device
    Since it is very cumbersome or impossible to do everything with the remote control I recommend to use ScrCpy.
    This allows you to easily control your device from your computer using mouse and keyboard.

    After installation you can connect to your device with adb and enter 'scrcpy' in your console. You should instantly see the screen of your TV on your computer.


    Installing 'Automate'
    The app I recommend for the automation is called 'Automate'. It is free, but sadly can't be directly installed from the app store on Android TV (because of compatibility).

    To avoid this limitation you can download the APK from e.g. Apkmirror and install it manually via ADB.
    adb install .\path\to\the\downloaded\apk\Automate_v1.32.6.apk

    While you are at it you can also give the app some privileges which it needs later to read the system logs and to start the apps.

    adb shell pm grant com.llamalab.automate android.permission.SYSTEM_ALERT_WINDOW
    adb shell pm grant com.llamalab.automate android.permission.READ_LOGS

    To start Automate you need a launcher that can see sideloaded apps. I recommend the X-plore File Manager since it's also a good file manager and can be easily installed from the app store.

    ( There are also other alternatives like 'Tasker' instead of 'Automate', but since that is not free and activation doesn't work properly on a sideloaded app I can't recommend that. )


    Configuring 'Automate'
    After starting Automate you can create a new 'flow'. The goal of that flow is to monitor the system logs, and start your desired apps everytime it sees a button press message.

    That can be done mainly with a 'Log await' node that contains following configuration:
    Tag: WindowManager
    Message: .*interceptKeyTq keycode=(\d+).*
    Priority: Debug
    Logged message (array): keycode

    You can then use "Expression true?" nodes to check for the found value in keycode (e.g. for the Live TV button) ...
    Formula: =keycode[1] = "172"
    ... and start your desired app with "App start" nodes.
    Package: com.google.android.tv

    An example of a full flow can be found here: 📺🎛️ Remap Onn. Android TV remote buttons


    Conclusion
    After setting all this up the apps should start when you press the buttons.
    However the original app (or its installation view) also starts before it, so if you press the back button you will return to that app instead of the previously running app. To avoid that just use the home button instead.

    The Automate app will not automatically start if you reboot your Android TV device. If you want that you can activate that in the settings: 'Run on system startup'. But make sure that everything works perfectly before you do that!

    If you get stuck in a loop where you can't use other apps and also can't open and configure Automate anymore, you can use this command via ADB to disable all flows:
    adb shell am broadcast -a com.llamalab.automate.intent.action.STOP_FLOW -n com.llamalab.automate/.StartServiceReceiver
    1
    To start Automate you need a launcher that can see sideloaded apps.

    As a one-off, in case you don't want to install another app, you can always run:

    Code:
    adb shell am start -n com.llamalab.automate/.FlowListActivity
    1
    As a one-off, in case you don't want to install another app, you can always run:

    Code:
    adb shell am start -n com.llamalab.automate/.FlowListActivity

    I went to Settings > Apps > See all apps and then scrolled down and clicked 'Show system apps'. You can find Automate, and then click open to launch.
    1
    Thanks for your guide. Now my Xiaomi Stick 4K remotes Netflix, Prime Video and Patchwall buttons are changed to open other apps.

    Can you make Automate flow work like Button Mapper having also double click and long press open different apps.
    1
    Thanks for Idea. I have acer remote with netflix, youtube, primevideo and tiki live button. How to find keycode for these button in my acer remote because given keycode don't works
    Connect the output of the "Log await" with the "Toast show" node, and the output of that back into the "Log await". That will create a little message popup with the keycode everytime you press a button.