ACTION_HEADSET_PLUG broadcast delay

这一生的挚爱 提交于 2019-12-04 13:34:38

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4124368/action-headset-plug-broadcast-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!