title: How to send data from android to Host USB device
body: <p>Can anyOne help me with this code?</p>
  
  <p>I would like to transmit from android to USB. I Have some technical problems trying to send data from my android code to an external USB device.  I have the vendor and other info;</p>
  
  <p>This is my device vendor info: </p>
  
  
  
  <pre><code>&lt;resources&gt;
      &lt;usb-device
          class="0"
          product-id="30209"
          protocol="0"
          subclass="0"
          vendor-id="5263" /&gt;
  &lt;/resources&gt;
  
  
  
  String s = "55 AA 81 8 F7 A F5 0";
                      byte [] bytes = s.getBytes();
                      connection.bulkTransfer(endpoint, bytes, bytes.length, 0); //do in another thread
  </code></pre>
  
  <p>This is my code: </p>
  
  <pre><code>private void doYourOpenUsbDevice(final UsbDevice usbDevice) {
          // now follow line will NOT show: User has not given permission to
          // device UsbDevice
           final UsbDeviceConnection connection = mUsbManager.openDevice(usbDevice);
          // here is your device-
          if(usbDevice.getDeviceId()==2002)
          {
  
  
              Thread thread = new Thread(new Runnable() {
                  public void run() {
                      //call method to set up device communication
                      UsbInterface intf = usbDevice.getInterface(0);
                      connection.claimInterface(intf, false);
  
                      //connection settings
                      int op= connection.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset   //0x40
                      int op2= connection.controlTransfer(0x40, 0, 1, 0, null, 0, 0);//clear Rx  
                      int op3= connection.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
                      int op3b=  connection.controlTransfer(0x40, 0x02, 0x0000, 0, null, 0, 0);//control flow
  
                      int op4= connection.controlTransfer(0x40, 0x03, 0x001A, 0, null, 0, 0);// baud rate 115200
                      int op5= connection.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0);//8 bit
  
  
  
  
                      int endPts = intf.getEndpointCount();
  
                      for(int e = 0; e &lt; endPts; e++){
                          UsbEndpoint endpoint = intf.getEndpoint(e);
                          endpoint.getAttributes();
  
                          if( endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK){
                              if(endpoint.getDirection() == UsbConstants.USB_DIR_IN){
                                  input = endpoint;
                                  Log.d("Endpoint", "Got input");
  
  
                              }else if(endpoint.getDirection() == UsbConstants.USB_DIR_OUT){
                                  output = endpoint;
                                  Log.d("Endpoint", "Got output");
                              }                       
                          }
                      }
                     int f =  connection.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
                     int f2 = connection.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80,
                                                      0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);
                     System.out.println(f +"  "+ f2 ); 
                     }
                  });
              thread.start();
  
  
  
  
          }
      }
  </code></pre>
  
  <p>The thing is that i have an USB Infrared and my android device as well. My android device has 2 USB ports. I would like to send this bytes "55 AA 81 8 F7 A F5 0" to the Infrared Host. 
  I know that is a little bit complicated but thank you for all! </p>