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.