title: Open USB host communication on a device already connected at the launch of the application
body: <p>I'm developping an application and I need to manage a device using the usb host mode of my tablette.</p>
  
  <p>At this point, I could only activate the USB, at the connection of the device.
  Process step :</p>
  
  <ol>
  <li>No application launch, connection of the device.<br></li>
  <li>Android ask me if I wan't to launch my application<br></li>
  <li>I accept<br>
  Then the application start, and I could use the USB connection.</li>
  </ol>
  
  <p>But, it is not that I want to do :</p>
  
  <ol>
  <li>Tablet off, connect the device<br></li>
  <li>switch tablet on<br></li>
  <li>Launch manualy the application<br></li>
  <li>Initialise the usb connection with the device.<br></li>
  </ol>
  
  <p>The fact is, that actualy, I need to unconnect/connect manualy the usb on my tablet to have the connection, but me, in my case, the device will be already connected to the tablet, then i need to initialise the connection without unconnect/reconnect the usb.</p>
  
  <p>I have tryed the example provided by Google on the USB Host connexion page that speak about Broadcast receiver, but that don't work, or I don't understant it very well.</p>
  
  <p>My questions is:<br>
  Is there any method to open the connection to an usb host device, that is already connected ?
  <br>By witch way I need to search to find this dammed solution :D</p>
  
  <p>Here the code that is already implemented to help at understand my problem :</p>
  
  <p>manifest.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="..."
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="14"
          android:targetSdkVersion="13" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/..." 
          android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" &gt;
  
          &lt;activity
              android:name="...Activity"
              android:configChanges="orientation|keyboardHidden|screenSize"
              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;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The file res/xml/device_filter.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;usb-device vendor-id="5455" product-id="8238" /&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>Then the onResume() in my Activity :</p>
  
  <pre><code>@Override
  protected void onResume() {
      super.onResume();
  
      Intent intent = getIntent();
      String action = intent.getAction();
  
      if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
  
          UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
          UsbManager usbManager = (UsbManager) activity.getSystemService(Context.USB_SERVICE);
  
      } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
      }
  }
  </code></pre>
  
  <p>And at the end my method that allow to make the connection :</p>
  
  <pre><code>protected void open(Object o) throws DeviceException {
      if (device != null &amp;&amp; device.getVendorId() == 5455 &amp;&amp; device.getProductId() == 8238) {
          int nbEndPoint = 0;
          for (int i = 0; i &lt; device.getInterfaceCount(); i++) {
              UsbInterface usbInterface = device.getInterface(i);
  
              for (int j = 0; j &lt; usbInterface.getEndpointCount(); j++) {
                  UsbEndpoint usbEndPoint = usbInterface.getEndpoint(j);
                  nbEndPoint++;
                  switch (nbEndPoint) {
                  case 1:
                      this.pipeWriteData = usbEndPoint;
                  case 2:
                      this.pipeReadCommandResult = usbEndPoint;
                  case 3:
                      this.pipeReadAutoStatus = usbEndPoint;
                  case 4:
                      this.pipeReadImageData = usbEndPoint;
                  }
              }
          }
  
          usbConnection = manager.openDevice(device);
          if (usbConnection == null || !usbConnection.claimInterface(device.getInterface(0), true)) {
              usbConnection = null;
              throw new DeviceException(DeviceException.UNKNOW_ERROR);
          }
      }
  }
  </code></pre>