title: Android: Receive UsbDevice from intent
body: <p>I'm messing about with the USB host, and following the guidelines <a href="http://developer.android.com/guide/topics/connectivity/usb/host.html" rel="noreferrer" title="Android Developers">on the Android Developers</a> site I've managed to create a Hello World that starts up once a particular USB device is plugged in.  However, when I try and "...obtain the UsbDevice that represents the attached device from the intent" it returns null:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Intent intent = new Intent();
      UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
  
  
      // device is always null
      if (device == null){Log.i(TAG,"Null device");}
  </code></pre>
  
  <p>Here's my manifest:</p>
  
  <pre><code>&lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.example.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&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;
      &lt;/application&gt;
  </code></pre>
  
  <p>And my xml/device_filter.xml (I know these are the correct VID and PID because I've got a similar app working using the enumeration method described <a href="http://developer.android.com/guide/topics/connectivity/usb/host.html" rel="noreferrer" title="Android Developers">on the Android Developers</a> site):</p>
  
  <pre><code>&lt;resources&gt;
      &lt;usb-device vendor-id="1234" product-id="1234"/&gt;
  &lt;/resources&gt;
  </code></pre>