Android: External Hardware Buttons Help/Question

Thread Starter

Yangui

Joined Oct 3, 2015
8
What I would like to do is use 4 external hardware buttons to be able to assign 4 different stock apps, on an Android phone to activate.
For example:
Code:
if Button 1 start Skype
if Button 2 start Media Player
if Button 3 start App X
if Button 4 start App Y
I have done Google search’s on this subject and come across many ways to be only control the volume or the media player controls via an external keyboard on USB or Bluetooth.
I have built a couple of HID devices with an Adafruit Trinket and an Arduino Leonardo but the most I can get them to do is control volume, medial play, wake up from screen sleep or put it to sleep based on the key code tables. https://source.android.com/devices/input/keyboard-devices.html
I am guessing (probably stupidly) that the Android framework has a file in it's depth that keeps a log of the touch screen app positions and locations or something similar ,
Any and all help is appreciated, I am great with hardware but not software programming.
 

andre_teprom

Joined Jan 17, 2016
31
Considering that Android is a language based on Java, by definition has an access to very limited hardware resources, one of the options to achieve the task is programming directly on Linux, but in this case you would be running out the Android platform, which is not recommended.

Android has a wide range of sensors documented in their SDK, but probably not all will be available on different devices. Ideally you have to list in each of the 2 devices what sensors are common to both, and then work with this option.

Another option would be using the own manufacturer drivers, as is the case with Samsung that provides some options, the most interesting in your case, the Bluetooth, but then the program would become no longer be compatible on different devices, because each one would use a separate API.

As far as possible, try to make some "button" application in the device screen.
 

MrSoftware

Joined Oct 29, 2013
2,188
My android development is limited so consider that when you read this; I think you have 2 parts. First you need to make a hardware device that integrates with android. Decide how you want it to connect. BlueTooth, WiFi, WiFi Direct, USB, etc.. First get your 4 buttons working and get that talking with android, so that you know how to integrate the hardware buttons with android.

Second, once your buttons are working, you need to create an android "service" application to monitor the buttons. A service runs in the background all the time. The service will monitor your buttons, and when it detects a button push it will send an "intent" to start the specified android application.

Read up on how android works. Applications can send "intents" to start other applications, or to accomplish specific tasks (take a photo, etc..). Check out the android documentation and examples. I was able to create BlueTooth and WiFi Direct demos using online examples and android studio.
 

Thread Starter

Yangui

Joined Oct 3, 2015
8
Thanks for the reply for the 1st part with hardware I have got it working using an Arduino with 4 buttons to control Volume up and down, media play and skip to next track via USB .
OK, It's the second part on creating a service application and figure out how to use intent is what I need to tackle. This is just the direction nudge I needed .

My android development is limited so consider that when you read this; I think you have 2 parts. First you need to make a hardware device that integrates with android. Decide how you want it to connect. BlueTooth, WiFi, WiFi Direct, USB, etc.. First get your 4 buttons working and get that talking with android, so that you know how to integrate the hardware buttons with android.

Second, once your buttons are working, you need to create an android "service" application to monitor the buttons. A service runs in the background all the time. The service will monitor your buttons, and when it detects a button push it will send an "intent" to start the specified android application.

Read up on how android works. Applications can send "intents" to start other applications, or to accomplish specific tasks (take a photo, etc..). Check out the android documentation and examples. I was able to create BlueTooth and WiFi Direct demos using online examples and android studio.
 
What I would like to do is use 4 external hardware buttons to be able to assign 4 different stock apps, on an Android phone to activate.
For example:
Code:
if Button 1 start Skype
if Button 2 start Media Player
if Button 3 start App X
if Button 4 start App Y
I have done Google search’s on this subject and come across many ways to be only control the volume or the media player controls via an external keyboards on USB or Bluetooth.
I have built a couple of HID devices with an Adafruit Trinket and an Arduino Leonardo but the most I can get them to do is control volume, medial play, wake up from screen sleep or put it to sleep based on the key code tables. https://source.android.com/devices/input/keyboard-devices.html
I am guessing (probably stupidly) that the Android framework has a file in it's depth that keeps a log of the touch screen app positions and locations or something similar ,
Any and all help is appreciated, I am great with hardware but not software programming.
hi there. do you found a solution? i need the same thing for a project.
 
Top