title: android usb UsbDeviceConnection.bulkTransfer returns -1
body: <p>I am trying to send commands to a POS printer from my android tablet. I have been able to get the basic connections wroking but now when I try to send data to the printer, the bulkTransfer returns -1. Please help me understand what is going on. The following is a modified broadcast receiver taken from the android site where I do all the data transfer.</p>
  
  <pre><code>private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
      public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          if (ACTION_USB_PERMISSION.equals(action)) {
              synchronized (this) {
                  UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
  
                  if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                      if(device != null){
                        //call method to set up device communication
  
                          if(device.getVendorId() != 1659)
                              return;
  
                          UsbInterface intf = device.getInterface(0);
                          UsbEndpoint endpoint = intf.getEndpoint(0);
                          int direction = endpoint.getDirection();                            
                          UsbDeviceConnection connection = mUsbManager.openDevice(device);
                          connection.claimInterface(intf, forceClaim);
  
                          bytes = new byte[]{27, 64};
  
                          //**This returns -1 always**
                          int ret = connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT); 
  
                          if(ret &lt; 0)
                          {
                              Log.d("WTF", "Error happened!");
                          }
                          else if(ret == 0)
                          {
                              Log.d("WTF", "No data transferred!");
                          }
                          else
                          {
                              Log.d("WTF", "success!");
                          }
                     }
                  } 
                  else {
                      Log.d(TAG, "permission denied for device " + device);
                  }
              }
          }
      }
  };
  </code></pre>