Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SD card files updated programmatically are not updated in windows explorer

My application does file operations on the SD card (delete or update file). But when I connect the device to Windows 7 through USB, I do not see any changes. However I can confirm files where updated or deleted with adb shell.

I use an ASUS eee Pad with Android 3.0.

It seems devices running Android 3.0 have a different way to provide access to the file system (MTP instead of USB Mass Storage). I also read about how we can use MediaScannerConnection.scanFile to refresh the content of Windows File Explorer when adding a new file.

But how to trigger a refresh when files are deleted or updated?

I tried MediaScannerConnection.scanFile on the deleted file but it only creates an entry with size 0. MediaScannerConnection.scanFile on the whole folder does not work either.

Thank you for your help.

G.

like image 433
Georges Avatar asked Dec 21 '11 15:12

Georges


1 Answers

So, as mentioned in the comment before. For now the best I've found is

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));

After a file was deleted or updated seems to work.

However, the device must be disconnected from USB. Otherwise you need to unplug and replug the device to see the changes.

NOTE: On some devices this may trigger a onResume event on the current activity.

like image 98
Georges Avatar answered Nov 14 '22 23:11

Georges