So, I’ve upgraded my phone to Android 2.2 and noticed that my Say Time application stopped working. So I did some research into why. Apparently the old system of MEDIA_BUTTON intent priorities wasn’t good enough for Google and they decided to change it to another, very different, method. Here’s how it works:

  • Any Android application can request that it become the current MediaButtonReceiver. This puts that application onto the stack and it becomes the SOLE receiver of media button presses.

  • If another application comes along and requests to be the MediaButtonReceiver, the current application is never sent any MEDIA_BUTTON events.

In my application, I had simply set it to be a MEDIA_BUTTON intent receiver with a high priority. And then when I got a press, I would either abort the broadcast (become the sole receiver) or choose not to abort the broadcast (passing it on to any other applications interested in getting MEDIA_BUTTON presses). This allowed my application to cooperate nicely with other applications using that button (on the headset) as input.

Now, my application is no longer able to easily cooperate with other applications. I could start a thread that calls registerMediaButtonReciever() and makes sure my application is always the SOLE receiver, then unregister again to allow the last receiver to get their presses again. When the unregister is called, the previous application that has registered becomes the SOLE receiver once again. But, the fact that I have to have a thread running all the time whether the button is pressed or not means my application will consume battery power, and I don’t like that.

I looked at the source code for the Music application, and it calls registerMediaButtonReceiver() every time a new music track begins playing. This basically steals the MEDIA_BUTTON events from any other application that might want to get them.

I have no idea how I would be able to influence Google to change their API to allow some way of knowing when another application has registered thereby replacing the current media button receiver. I think if I had that type of API, I would be able to avoid having to write a thread to set it all the time.

I’ll be trying the thread approach, and hopefully it solves my problem without becoming a battery drain. If anyone has any other ideas, please let me know. Thanks.