ACTION_HEADSET_PLUG broadcast delay
Asked Answered
L

2

5

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?

Lamellirostral answered 8/11, 2010 at 13:43 Comment(0)
L
8

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

Lamellirostral answered 24/11, 2010 at 13:20 Comment(1)
Hehe, I find it great that the very answer (which I'm not saying is wrong) that told you no, led to your little work around. Congratz!Fieldwork
B
3

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.

Balata answered 8/11, 2010 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.