headset button

1279 views
Skip to first unread message

Brodsky

unread,
Jan 30, 2009, 2:20:39 PM1/30/09
to Android Developers
Hi! Does anyone know how to tell when the headset button is being
pressed? I'd like to support the usb headsets and possibly bluetooth
headsets. My app is a media player and ideally, I could register it
somewhere so that if no app that uses the headset button has focus it
button press would act as a play/pause command in my app. If the phone
is ringing or a call is in progress, I'd like to be sensitive to that
and let the button do what it normally does: pickup and hang up
calls. we've been trying to chase the button down using this:

IntentFilter headsetFilter = new IntentFilter
(Intent.ACTION_HEADSET_PLUG);
headsetFilter.addAction
("android.intent.action.HEADSET_STATE_CHANGED");
headsetFilter.addAction("android.bluetooth.intent.HEADSET_STATE");
headsetFilter.addAction
("android.bluetooth.intent.HEADSET_STATE_CHANGED");
headsetFilter.addAction
("android.bluetooth.intent.action.MODE_CHANGED");
headsetFilter.addAction("android.intent.action.MODE_CHANGED");

no luck as of yet. Any help would be greatly appreciated! Thanks!

deep...@googlemail.com

unread,
Jan 31, 2009, 5:07:10 AM1/31/09
to Android Developers

Nick Pelly

unread,
Feb 1, 2009, 4:01:20 AM2/1/09
to android-d...@googlegroups.com
For wired headsets, you can use Intent.ACTION_MEDIA_BUTTON as mentioned in the other thread. This is how the built in media app does pause/play on wired headset button presses, and where I recommend that you hook in.

For Bluetooth headsets, they do not work like you think. There is no 'button pressed event' sent by the headset. We don't know when the button is pressed. Instead the headset maps its buttons presses to commands depending on its state machine. We receive commands, not button presses from the headset.

Nick

Porting beginner

unread,
Feb 18, 2010, 3:05:20 AM2/18/10
to android-d...@googlegroups.com
On Sun, Feb 1, 2009 at 1:01 AM, Nick Pelly <npe...@google.com> wrote:
For wired headsets, you can use Intent.ACTION_MEDIA_BUTTON as mentioned in the other thread. This is how the built in media app does pause/play on wired headset button presses, and where I recommend that you hook in.

For Bluetooth headsets, they do not work like you think. There is no 'button pressed event' sent by the headset. We don't know when the button is pressed. Instead the headset maps its buttons presses to commands depending on its state machine. We receive commands, not button presses from the headset.

Nick

Hi,
Can you please write in some more details relate to headset button mapping ?
I got stuck here, I don't know how to go ahead. I am trying to find out where I should hook my headset button press event ?




On Sat, Jan 31, 2009 at 2:07 AM, deep...@googlemail.com <deep...@googlemail.com> wrote:

you may want to look at

http://groups.google.com/group/android-developers/browse_thread/thread/1c64cf65f87c9895/1d9464c96b91dbd8?show_docid=1d9464c96b91dbd8



On Jan 30, 8:20 pm, Brodsky <peter.brod...@gmail.com> wrote:
> Hi!  Does anyone know how to tell when the headset button is being
> pressed?  I'd like to support the usb headsets and possibly bluetooth
> headsets.  My app is a media player and ideally, I could register it
> somewhere so that if no app that uses the headset button has focus it
> button press would act as a play/pause command in my app. If the phone
> is ringing or a call is in progress, I'd like to be sensitive to that
> and let the button do what it normally does: pickup and hang up
> calls.  we've been trying to chase the button down using this:
>
> IntentFilter headsetFilter = new IntentFilter
> (Intent.ACTION_HEADSET_PLUG);
> headsetFilter.addAction
> ("android.intent.action.HEADSET_STATE_CHANGED");
> headsetFilter.addAction("android.bluetooth.intent.HEADSET_STATE");
> headsetFilter.addAction
> ("android.bluetooth.intent.HEADSET_STATE_CHANGED");
> headsetFilter.addAction
> ("android.bluetooth.intent.action.MODE_CHANGED");
> headsetFilter.addAction("android.intent.action.MODE_CHANGED");
>
> no luck as of yet.  Any help would be greatly appreciated!  Thanks!



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---




--
Thanks

Porting beginner

unread,
Feb 20, 2010, 1:05:52 AM2/20/10
to android-d...@googlegroups.com
On Sun, Feb 1, 2009 at 1:01 AM, Nick Pelly <npe...@google.com> wrote:
For wired headsets, you can use Intent.ACTION_MEDIA_BUTTON as mentioned in the other thread. This is how the built in media app does pause/play on wired headset button presses, and where I recommend that you hook in.


For Bluetooth headsets, they do not work like you think. There is no 'button pressed event' sent by the headset. We don't know when the button is pressed. Instead the headset maps its buttons presses to commands depending on its state machine. We receive commands, not button presses from the headset.

Nick

Hi Nick,

My headset driver maps button press to KEYCODE_CALL.

I have resolved this issue with condition check in PhoneWindowsManager.c.
Now I can use my wired headset button to either receive or end incoming call. is this proper way to fix this issue ?

 


On Sat, Jan 31, 2009 at 2:07 AM, deep...@googlemail.com <deep...@googlemail.com> wrote:

you may want to look at

http://groups.google.com/group/android-developers/browse_thread/thread/1c64cf65f87c9895/1d9464c96b91dbd8?show_docid=1d9464c96b91dbd8



On Jan 30, 8:20 pm, Brodsky <peter.brod...@gmail.com> wrote:
> Hi!  Does anyone know how to tell when the headset button is being
> pressed?  I'd like to support the usb headsets and possibly bluetooth
> headsets.  My app is a media player and ideally, I could register it
> somewhere so that if no app that uses the headset button has focus it
> button press would act as a play/pause command in my app. If the phone
> is ringing or a call is in progress, I'd like to be sensitive to that
> and let the button do what it normally does: pickup and hang up
> calls.  we've been trying to chase the button down using this:
>
> IntentFilter headsetFilter = new IntentFilter
> (Intent.ACTION_HEADSET_PLUG);
> headsetFilter.addAction
> ("android.intent.action.HEADSET_STATE_CHANGED");
> headsetFilter.addAction("android.bluetooth.intent.HEADSET_STATE");
> headsetFilter.addAction
> ("android.bluetooth.intent.HEADSET_STATE_CHANGED");
> headsetFilter.addAction
> ("android.bluetooth.intent.action.MODE_CHANGED");
> headsetFilter.addAction("android.intent.action.MODE_CHANGED");
>
> no luck as of yet.  Any help would be greatly appreciated!  Thanks!



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---




--
Thanks

skyhigh

unread,
Feb 22, 2010, 12:17:38 AM2/22/10
to Android Developers
For a media application you need to register a broadcast receiver for
Intent.ACTION_MEDIA_BUTTON and then when the callback is called you
want to handle the following key codes:

These key codes are sent from Bluetooth devices such as headphones and
in car stereos:
KEYCODE_MEDIA_PLAY_PAUSE
KEYCODE_MEDIA_NEXT
KEYCODE_MEDIA_PREVIOUS
KEYCODE_MEDIA_FAST_FORWARD
KEYCODE_MEDIA_REWIND
KEYCODE_MEDIA_STOP

This key code is sent from the wired headset call button:
KEYCODE_HEADSETHOOK

Good luck!

Pasomas

unread,
Mar 15, 2011, 5:39:50 PM3/15/11
to android-d...@googlegroups.com


Please could you post a snippet?
I am not getting any result trying to catch those
key codes...i'm working with Galaxy Tab + Samsung HM1500 Bluetooth headset

Thank you all!

Reply all
Reply to author
Forward
0 new messages