I have a working Android Push-to-Talk application which I am now enhancing to support a hardware-based PTT button. I am working with Motorola LEX 700 handsets, and found that onKeyDown() and onKeyUp() report the PTT button as KEYCODE_BUTTON_L1 - the left trigger button on a game controller.
My application consists of an Activity, a BroadcastReceiver, and three Services. The Activity is only a UI and it used to select the PTT channel, adjust the volume, see the various statuses, etc. It also has a large touch target used as a soft PTT button. The BroadcastReceiver listens for changes in the access network connectivity. One of the Services acts as the main controller and contains all of the application logic. The other two services are used for managing network IO and managing the device's audio resources.
It was trivial to watch for key events for hardware button and perform the same actions as when the touch target was pressed and released. The application can now use the hardware PTT button.
Now for my problem. Key events are only observable in an Activity (or View), and only while the the Activity (or View) has focus. I want to be able to use the hardware PTT button without the UI Activity running, or when the UI is not in focus. I am looking for any ideas how I might to be able to accomplish this.
Also, I did notice is what when my Activity was not in focus, that the hardware button presses got caught by a default handler - PhoneFallbackEventHandler - which printed a debug message that made me think that it is sending-out an Intent while the button was pressed and released. If this is the case, then I could probably catch that with my BroadcastReceiver.
06-10 15:23:29.224: D/PhoneFallbackEventHandler(654): PTT key DOWN, raising key down intent..
06-10 15:23:30.052: D/PhoneFallbackEventHandler(654): PTT key UP, raising key up intent..
I don't see anything like it in the standrd list of broadcast intents. Is there an easy way to discover it somehow?