title: BroadcastReceiver monitoring for a specific USB device attached
body: <p>I have an activity that starts when a specific USB device is attached, as specified in a device filter file, which works great:</p>
  
  <pre><code>&lt;activity
              android:name="com.mycompany.DerpApp.MainActivity"
              android:launchMode="singleTask"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"  /&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data
                  android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                  android:resource="@xml/device_filter" /&gt;
          &lt;/activity&gt;
  </code></pre>
  
  <p>I also have a service where I want to monitor for connect and disconnect. I have BroadcastReceivers wired up, and they fire upon device attach and detach. However, I want these broadcast receivers to trigger when only a device as specified in my device_filter.xml is attached/detached.</p>
  
  <pre><code>m_usbDisconnectReceiver = new UsbDisconnectReceiver();
  registerReceiver(m_usbDisconnectReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));
  
  m_usbConnectReceiver = new UsbConnectReceiver();
  registerReceiver(m_usbConnectReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED));
  </code></pre>
  
  <p>I am unsure of how to attach my device_filter file to the programatically created Broadcast Receiver. Is there something I can do in the IntentFilter for this? I think that the Intent that is provided to the onReceive() has a UsbDevice as one of its extras, but it would be best if I could filter it out so the event doesn't fire. And if that's not possible, how can I check to see if the UsbDevice is a part of my device_filter?</p>