Way to ensure delivery of Action HEADSET_PLUG for ZTE T815 Android phone

*爱你&永不变心* 提交于 2019-12-12 02:02:55

问题


I have registered a BroadcastReceiver to receive ACTION_HEADSET_PLUG which works fine for most devices, ie it is called whenever the headset is plugged or unplugged. But on others eg the ZTE T815, the Intent is never sent/received when the headset is plugged/unplugged.

For reference here is the code for the receiver registration:

private final BroadcastReceiver headsetPlugReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Received intent=" + intent);
        if (intent.getAction().equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG)) {
            // do stuff
        }
    }
};

public void onCreate(Bundle savedState) {
    super.onCeate(savedState);
    // ...
    registerReceiver(headsetPlugReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
}

Further info: The Intent is dispatched but only after the HEADSET_HOOK command is fired on the headset.

And when the Intent is dispatched

final int microphone = intent.getIntExtra("microphone", 0);

always returns 0 (ie no microphone).

So

  1. Is there some config/code that can force the delivery of this Intent?
  2. How do I get the Intent to correctly report whether a microphone exists or not?

回答1:


It turns out the ZTE T815 has an OMTP TRRS config for its audio socket instead of CTIA/AHJ like every other modern Android device.

See http://en.wikipedia.org/wiki/Phone_connector_%28audio%29

A sad state of affairs, especially when trying to use audio feed inpout across products.



来源:https://stackoverflow.com/questions/28619583/way-to-ensure-delivery-of-action-headset-plug-for-zte-t815-android-phone

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