Android: External Hardware Buttons Help/Question

Discussion in 'Programmer's Corner' started by Yangui, Feb 10, 2016.

  1. Yangui

    Thread Starter New Member

    Oct 3, 2015
    8
    2
    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 (Text):
    1. if Button 1 start Skype
    2. if Button 2 start Media Player
    3. if Button 3 start App X
    4. 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.
     
  2. andre_teprom

    Member

    Jan 17, 2016
    31
    9
    Which mobile manufacturer/model are you using ?
     
    Yangui likes this.
  3. Yangui

    Thread Starter New Member

    Oct 3, 2015
    8
    2
    I am using a rooted Samsung Galaxy Note 4 running Android 5 and I also use a rooted Lenovo A3000 7" tablet running Android 4.2
     
  4. andre_teprom

    Member

    Jan 17, 2016
    31
    9
    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.
     
  5. MrSoftware

    Active Member

    Oct 29, 2013
    504
    124
    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.
     
    Yangui likes this.
  6. Yangui

    Thread Starter New Member

    Oct 3, 2015
    8
    2
    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 .

     
Loading...