Solving Invisible MTP files problem.

suggest change

If you create files for export over USB to a desktop with MTP, newly created files may not show up immediately in the desktop file explorer. To make new files visible, you need to call MediaScannerConnection:

File file = new File(Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_DOCUMENTS), "theDocument.txt");
FileOutputStream out = new FileOutputStream(file);

// ... write the document

out.close();
MediaScannerConnection.scanFile(this, new String[] {file.getPath()}, null, null);
this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
        Uri.fromFile(file)));

This MediaScannerConnection call code works for files only, not for directories. The problem is described in this Android bug report. This may be fixed for some version in the future, or on some devices.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents