Search code examples
androidbroadcastreceiverheadset

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


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?

Solution

  • 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.