Take the 2-minute tour ×

i'm trying to simply write a simple XML file to the SD card and i noticed that my Nexus 4 does write the file, but it is not viewable via the MTP protocol using Windows 7.


public void onCreate(Bundle savedInstanceState) {

    CustomerQueryRqType customerQueryRequest = new CustomerQueryRqType();
    Serializer serializer = new Persister();
    File myFile = new File(Environment.getExternalStorageDirectory() + "/customerQueryRequest.xml");

    try {
        boolean created = myFile.createNewFile();
        serializer.write(customerQueryRequest, myFile);
    } catch (Exception e) {

i can see the file on the phone itself with Astro File Manager:

but Windows doesn't see it...:

adb shell on the directory shows:

ls -l
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Alarms
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Android
drwxrwxr-x root     sdcard_rw          2012-11-21 19:30 DCIM
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Download
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Movies
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Music
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Notifications
drwxrwxr-x root     sdcard_rw          2012-11-19 12:06 Pictures
drwxrwxr-x root     sdcard_rw          1970-01-16 20:51 Podcasts
drwxrwxr-x root     sdcard_rw          2012-11-19 13:22 Ringtones
drwxrwxr-x root     sdcard_rw          2012-11-19 14:33 bluetooth
-rw-rw-r-- root     sdcard_rw       79 2012-12-05 22:26 customerQueryRequest.xml
drwxrwxr-x root     sdcard_rw          2012-11-20 02:50 data
-rw-rw-r-- root     sdcard_rw    11394 2012-11-19 13:54 eightpen_custom_gestures
drwxrwxr-x root     sdcard_rw          2012-11-19 13:17 media

what's going on with my Nexus 4? why's it hiding my things from Windows?

share|improve this question
add comment

7 Answers

up vote 38 down vote accepted

Seems to be a known issue affecting Android USB file access over MTP. The MTP cache gets out of date until a reboot of the phone.

A workaround is:

  • Clear the "Media Storage" app's data
  • Use the SDrescan app to force an update

Or just avoid using USB at all. The issue does not affect other methods of accessing the files. For example, try AirDroid to transfer files.

share|improve this answer
Install SDrescan, run it: fixed! Thanks a lot –  PiTheNumber Jul 6 '13 at 15:05
add comment

You can use the following code after file close

MediaScannerConnection.scanFile(this, new String[] { file.getAbsolutePath() }, null, null);


share|improve this answer
Perfect. This should be the solution to this question. –  Sorcerer Feb 3 at 15:15
add comment

notice /storage/emulated. Android 4.2 has some funky emulated per-app/user access stuff going on, for example a separate /sdcard/ for each user. Try moving the file to /sdcard/ instead of the emulated sdcard that is shown.

share|improve this answer
everything is a link to /storage/emulated/legacy anyway, which itself is a link to /mnt/shell/emulated/0 which contains the file. –  moonlightcheese Dec 7 '12 at 13:55
add comment

On Xperia Z below code worked just fine:

  String screenShotFile = "....";
  activity.sendBroadcast(new Intent(
        Intent.ACTION_MEDIA_MOUNTED, Uri

for 4.4+ use:

activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,

(unfortunalelly I dont remember if I have tested it well enough)


share|improve this answer
This will cause a SecurityException on OS 4.4+ –  markostamcar Dec 7 '13 at 20:38
Yep, this works on < 4.4 but unfortunately won't work on 4.4+. –  Learn OpenGL ES Feb 20 at 19:44
updated for 4.4+ –  marcin_j Feb 20 at 20:02
add comment

The simple code proposed to question How can I refresh MediaStore on Android? does the necessary update of MediaStore, if called after I put a file on external storage. Content on my Nexus 4 is refreshed instantly in Window 7 file explorer.

share|improve this answer
Just experienced, that it might stop updating eventually. –  stephan Jul 3 '13 at 15:35
unfortunately it does not work on Xperia Z –  marcin_j Jul 29 '13 at 17:10
add comment

The above answers are fine for creating the file. If you later delete the file and want that change to be reflected as well, you can do one of the following; let's first cover two solutions that seem like they work, but will cause problems on some devices. The first one is to scan the deleted file:

context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));

This works on many devices for deleted files, but on some devices it'll actually cause a new 0-byte file to be created, which probably isn't what you want. In that case, if you're running on < 4.4 KitKat, you can do this:

context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(folder)));

Where folder is equal to file.getParentFile(). Unfortunately, on KitKat 4.4 and above, this will cause a SecurityException to get thrown, so for those devices, you can try deleting directly from the Media Store:

final Uri externalFilesUri = Files.getContentUri("external");
context.getContentResolver().delete(externalFilesUri, Files.FileColumns.DATA + "=?", new String[] {file.getAbsolutePath()});

I've tested this one as a workaround for ACTION_MEDIA_MOUNTED not working on KitKat, and it works in my testing on the Nexus 5.

share|improve this answer
add comment

Recently I faced with the same problem but some additional research helped find hidden files. It seems that Google has made some changes in storage structure. All these files were moved to another folder This Computer\HTC One\Internal Storage\storage\emulated\0. But it's strange that not all files were moved.

Android 4.4.2

Hope it helps :)

share|improve this answer
add comment

Your Answer


