Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACTION_HEADSET_PLUG broadcast delay

I have my own BroadcastReceiver instance for Intent.ACTION_HEADSET_PLUG action. There is about 1-2 seconds delay between actual physical unplugging a headset and a moment when my BroadcastReceiver is notified about that.

IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
registerReceiver(new BroadcastReceiver() {

  @Override
  public void onReceive(Context context, Intent intent) {
    // my code here
  }
}, filter);

Any ideas how to decrease the delay?

like image 897
plugmind Avatar asked Nov 08 '10 13:11

plugmind


2 Answers

Handling AudioManager.ACTION_AUDIO_BECOMING_NOISY broadcast did the trick :) Its intent is broadcast directly after headset is unplugged without any delay.

like image 85
plugmind Avatar answered Oct 23 '22 18:10

plugmind


You are out of luck.

The delay is hardcoded in the framework, look in

frameworks/base/services/java/com/android/server/HeadsetObserver.java

The delay is 1000 ms, due to the risk of having garbage in the audio pipeline.

like image 35
Robert Avatar answered Oct 23 '22 18:10

Robert