Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top