Search code examples
androidaudiousbbroadcastreceivermicrophone

Can't receive android.intent.action.USB_DGTL_MIC_PLUG


Here is a funny one. Android 4.1.1. When a USB mic is connected (state = 1)/disconnected (state = 0) the following broadcast is sent:

VERBOSE/WiredAccessoryObserver(260): android.intent.action.USB_DGTL_MIC_PLUG: state: 1 name: usb_audio_capture
VERBOSE/AudioService(260): Broadcast Receiver: Got ACTION_USB_DGTL_MIC_PLUG, state = 1

Why does my broadcast receiver fail to recieve this? I do start the main activity manually.

<receiver android:name=".UsbMic" android:enabled="true" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.USB_DGTL_MIC_PLUG" />
    </intent-filter>
</receiver>


public class UsbMic extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("Test", "USB Mic");
    }
}

Solution

  • I can't find USB_DGTL_MIC_PLUG in the Android API as a system intent, so I can't verify it on my own (seems to be a device specific thing). Some intents can only be received, when you register a receiver from code instead of your manifest. Have you tried creating a custom reciever and starting it manually from your activity?

    IntentFilter filter = new IntentFilter();
    filter.addAction("android.intent.action.USB_DGTL_MIC_PLUG");
    
    receiver = new UsbMic();       
    registerReceiver(receiver, filter);