5

I have one problem with detection if headphones are currently plugged in. I use Intent.ACTION_HEADSET_PLUG and it works good. I start a service and in onCreate() method I register my reciever via registerReceiver(). Most of the time I recieve ACTION_HEADSET_PLUG broadcast immediately, so I know whether headphones are plugged or not.

But sometimes (I am not sure why) I dont get this broadcast immediately after I register my reciever - so I dont know current state of headphones. Maybe I can just assume that in that case they are not connected - but I am not sure if it is 100% thuth. So I found AudioManager#isWiredHeadsetOn() method and I also added required permission MODIFY_AUDIO_SETTINGS. The problem is that it only works correctly with headset (headphones + mic), when just headphones are plugged it returns false every time. Please, do you have any idea how to solve this? I am developing for android 2.1.

Perry_ml
  • 495
  • 5
  • 16
  • Check http://stackoverflow.com/questions/13610258/how-to-detect-when-a-user-plugs-headset-on-android-device-opposite-of-action-a?answertab=oldest#tab-top – user3106119 Jul 08 '14 at 04:46

0 Answers0