title: Reading the data from Usb in android
body: <p>Please forgive me if I am not be able to elaborate my problem clearly.
  I am trying to communicate with usb device and the which is getting successfully done
  but i want to read from the usb device.
  the code for the transferring the command is as follows.</p>
  
  <pre><code>    public final static String TAG = "UsbClient";
  private UsbManager mUsbManager;
  private final int VID = 0x1fc9;
  private final int PID = 0x0003;
      private int toggle = 0;
  
  
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_main_dummy,
              container, false);
  mUsbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
  mPermissionIntent = PendingIntent.getBroadcast(getActivity(), 0, new Intent(ACTION_USB_PERMISSION), 0);
  IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
      getActivity().registerReceiver(mUsbReceiver, filter);
  HashMap&lt;String, UsbDevice&gt; devlist = mUsbManager.getDeviceList();
      Iterator&lt;UsbDevice&gt; deviter = devlist.values().iterator();
  while (deviter.hasNext()) {
          UsbDevice d = deviter.next();
          print("Found device: "
                  + String.format("%04X:%04X", d.getVendorId(),
                          d.getProductId()));
          if (d.getVendorId() == VID &amp;&amp; d.getProductId() == PID) {
  
              mUsbManager.requestPermission(d, mPermissionIntent);
          }
  
  }   
  </code></pre>
  
  <p>The code for the Registered Receiver is</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() == VID &amp;&amp; device.getProductId() == PID) {
                                  print("Got permission for the device");
                                  permissionGranted = true;
                                  UsbInterface intf = device.getInterface(0);
                                  conn = mUsbManager.openDevice(device);
                                  //intf=device.getInterface(0);
  
                                  conn.claimInterface(intf, true);
  /*                              if (!conn.claimInterface(device.getInterface(1), true)) {
                                      print("Could not claim the interface");
                                      return;
                                  }
  */                              
                                  int i = conn.controlTransfer(0x21, 0x09, 0x0200, 0x0000, new byte[] { (byte) toggle }, 1, 0);
                                  endpoint=device.getInterface(0).getEndpoint(0);
                                  if (toggle == 0) {
                                      toggle = 1; 
                                  }
                                  else {
                                      toggle = 0;
                                  }
  
                                  if ((i == 0) || (i==1)) {
                                      print("transfer successful");
                                  }
                                  else {
                                      print("transfer failed");
                                  }
  
  
  
                              }
                         }
                      } 
                      else {
                          print("permission denied for device " + device);
                      }
                  }
              }
          }
      };   
  </code></pre>
  
  <p>Now i wanted to know the procedure to read the data from the usb device that is attached to the android tablet Using OTG cable.
  and one more thing how to obtain the endpoints for read and write to the usb device.</p>
  
  <p>Thanks in advance.</p>