title: Mtp/Ptp Android
body: <p>I'm trying to copy the files of my camera who use PTP to my tablet. I have use the android API MTPDevice 
  (<a href="https://developer.android.com/reference/android/mtp/MtpDevice.html#importFile%28int,%20java.lang.String%29" rel="nofollow noreferrer">https://developer.android.com/reference/android/mtp/MtpDevice.html#importFile%28int,%20java.lang.String%29</a>) , I have request necessary permission(android.mtp.MtpClient.action.USB_PERMISSION).</p>
  
  <p>I have open the device, the  function return true, and open the USBConnection (Connexion OK).</p>
  
  <p>I try to import all files of the camera in a temp Folder on my tablet (/mnt/sdcard/tmpFolder). The path exist on my tablet, but when i give it to the importFiles function I have the error : </p>
  
  <p>[LOGCAT]</p>
  
  <pre><code>MtpDevice: readObject: /mnt/sdcard/tmpFolder
  MtpDevice: open failed for /mnt/sdcard/tmpFolder
  Debug: File import KO
  </code></pre>
  
  <p>I have try with a path doesn't exist I have the message :</p>
  
  <p>[LOGCAT]</p>
  
  <pre><code>MtpDevice: readObject: /mnt/sdcard/tptp
  MtpDevice: readResponse failed
  Debug: File import KO
  </code></pre>
  
  <p>Someone can help me ?</p>
  
  <p>Thanks </p>
  
  <pre><code>  @Background
  @DebugLog
  public void getMTPDevice() {
      HashMap&lt;String, UsbDevice&gt; deviceList = manager.getDeviceList();
      Iterator&lt;UsbDevice&gt; deviceIterator = deviceList.values().iterator();
      if (deviceIterator.hasNext()) {
          UsbDevice usbDevice = deviceIterator.next();
          device = openDeviceLocked(usbDevice);
          if(device!=null){
                  File folder = returnTempFolderCamera();
                  if(folder.exists()){
                      Log.d("Debug", "Folder exist /mnt/sdcard/tmpFolder");
                      if(device.importFile(0,folder.getPath()))
                      {
                          Toast.makeText(this, "File import OK", Toast.LENGTH_LONG).show();
                          Log.d("Debug", "Files import OK");
                      }else {
                          Toast.makeText(this, "File import KO", Toast.LENGTH_LONG).show();
                          Log.d("Debug", "Files import KO");
                      }
                  }
          }
      }
  }/**
   * Opens the {@link android.hardware.usb.UsbDevice} for an MTP or PTP device
   * and return an {@link android.mtp.MtpDevice} for it.
   *
   * @param usbDevice
   *            the device to open
   * @return an MtpDevice for the device.
   */
  @DebugLog
  private MtpDevice openDeviceLocked(UsbDevice usbDevice) {
      String deviceName = usbDevice.getDeviceName();
      byte[] data = new byte[128];
      int TIMEOUT = 0;
      boolean forceClaim = true;
      // don't try to open devices that we have decided to ignore
      // or are currently asking permission for
      if (isCamera(usbDevice)
              &amp;&amp; !mRequestPermissionDevices.contains(deviceName)) {
          if (!manager.hasPermission(usbDevice)) {
              manager.requestPermission(usbDevice, mPermissionIntent);
              mRequestPermissionDevices.add(deviceName);
          } else {
              UsbInterface intf = usbDevice.getInterface(0);
              UsbEndpoint endpoint = intf.getEndpoint(0);
              UsbDeviceConnection connection = manager.openDevice(usbDevice);
              connection.claimInterface(intf, forceClaim);
              connection.bulkTransfer(endpoint, data, data.length, TIMEOUT);
              if (connection != null) {
                  MtpDevice mtpDevice = new MtpDevice(usbDevice);
                  if (mtpDevice.open(connection)) {
                      mDevices.put(usbDevice.getDeviceName(), mtpDevice);
                      return mtpDevice;
                  }
              }
          }
      }
      return null;
  }
          private File returnTempFolder(){
              File tmp = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/tmpFolder");
              return tmp;
          }
  </code></pre>