6

I want to check whether heaset is plugged in or not... I did it like this

 AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
 Log.i("am.isWiredHeadsetOn()", am.isWiredHeadsetOn()+"");

But i am always getting false value...

Why is this happening?

Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
coderslay
  • 13,960
  • 31
  • 73
  • 121
  • This actually should work fine. Can you check your code on other devices then Folio 100? – inazaruk Jun 06 '11 at 09:27
  • Yes i also have checked it on HTC wildfire too and it is giving false.. Is there any permission that i need to add? – coderslay Jun 06 '11 at 09:28
  • Are you testing this on the emulator or an actual device? And what Android OS do you have on the emulator or device? – Jon Jun 06 '11 at 09:22
  • I am testing this on Folio 100 Tablet and it has Android 2.2 – coderslay Jun 06 '11 at 09:22
  • It looks like it should work fine. Are you sure the AudioManager is working properly? Try playing a sound using it like: am.playSoundEffect(FX_KEY_CLICK); – Jon Jun 06 '11 at 09:34

1 Answers1

13

It looks like this is a bug. You will always get false when calling isWiredHeadsetOn unless your add MODIFY_AUDIO_SETTINGS permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
inazaruk
  • 74,247
  • 24
  • 188
  • 156