title: How to list files on USB OTG device
body: <p>I know how to do following:</p>
  
  <ul>
  <li>listen to attach and detach events of usb devices</li>
  <li>getting all attached devices</li>
  <li>getting permissions for a device</li>
  </ul>
  
  <p>So in the end I have an <code>UsbDevice</code> and I have permissions to read/write it. How to go on from here?</p>
  
  <p>I can open the device and get a <code>FileDescriptor</code> like following:</p>
  
  <pre><code> UsbManager manager = (UsbManager) activity.getSystemService(Context.USB_SERVICE);
   UsbInterface intf = device.getInterface(0);
   UsbEndpoint endpoint = intf.getEndpoint(0);
   UsbDeviceConnection connection = manager.openDevice(device);
   boolean interfaceClaimed = connection.claimInterface(intf, true);
   int fileDescriptor = connection.getFileDescriptor();
  </code></pre>
  
  <p><em>How can I work with this <code>FileDescriptor</code> now? Or how else can I access the files on the USB device?</em></p>
  
  <p><strong>EDIT</strong></p>
  
  <ul>
  <li><p><em>Solution for android &lt; 6</em>: Don't open a <code>UsbDeviceConnection</code> and just try to find the usb devices path. Still, then you have the problem to distinguish between multiple usb devices and don't know which path belongs to which device...</p></li>
  <li><p><em>Solution for android >= 6</em>: Use the Storage Access Framework, actually I don't know how this works yet...</p></li>
  </ul>