Problem Description:
Listening system broadcast Action_headset_plug, the headset pauses playback when unplugged, however, there is a delay in actual processing, the headset unplugged does not immediately pause playback, but delayed a few seconds before pausing
Workaround:
Monitor the audiomanager.action_audio_becoming_noisy to solve the problem of this delay
Public classEarphonereceiver extends Broadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {//if (intent.getaction (). Equals (Intent.action_headset_plug)) { if(Intent.getaction (). Equals (Audiomanager.action_audio_becoming_noisy)) {//Handling Events } }} Private voidRegisterearphonereceiver () {Earphonereceiver=NewEarphonereceiver (); Intentfilter Filter=NewIntentfilter (audiomanager.action_audio_becoming_noisy);//filter.addaction ("Android.intent.action.HEADSET_PLUG");Registerreceiver (Earphonereceiver,filter); }
Cons: No headphone insertion Event detected
Reference Blog: http://stackoverflow.com/questions/4124368/action-headset-plug-broadcast-delay/4267213#4267213
http://blog.csdn.net/mu399/article/details/38516039
Monitor headset removal broadcast delay ACTION_HEADSET_PLUG broadcast delay