2

I've got my code working using the isWiredHeadsetOn() method in AudioManager as long as I use the headset that came with my phone. If I use a pair of headphones without an inbuilt microphone, isWiredHeadsetOn() returns false, which I suppose is fair enough, but isn't what I want! Is there a way to detect both headsets and headphones?

Kieran
  • 860
  • 7
  • 12

1 Answers1

2

The best way is to use a broadcast receiver for ACTION_HEADSET_PLUG. Then you get events when the headset is connected or disconnected.

I think it should work for bluetooth devices but am not 100% sure to be honest.

siliconeagle
  • 7,379
  • 3
  • 29
  • 41
  • Thanks but I wanted to avoid doing that just in case there's a time where the event isn't fired in addition to maintaining a state in my app. oh well, this is probably the only way to do it. – Kieran Jul 07 '11 at 07:46
  • have your reciever recieve intent this requires – siliconeagle Jul 19 '11 at 02:39
  • Yeah, the problem is that ACTION_HEADSET_PLUG fires before BOOT_COMPLETED, at least on my phone. – Kieran Jul 20 '11 at 02:46