ACTION_HEADSET_PLUG broadcast delay
I have my own BroadcastReceiver
instance for In开发者_StackOverflowtent.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?
Handling AudioManager.ACTION_AUDIO_BECOMING_NOISY
broadcast did the trick :) Its intent is broadcast directly after headset is unplugged without any delay.
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.
精彩评论