2013-05-25

MTP database not update until device reboot

Android change the default connection from USB Mass Storage to MTP. But there is a known issue when using MTP.
If some apps create a file in sdcard, and these apps are not like camera, gallery..etc system apps. The MTP database will not update.
This will cause you cannot find this file via MTP after you connec USB cable with PC. Even you re-plug USB cable multiple times, until you reboot your device.

Workaround solution:
1. Manually clear "Media Storage" app data
2. Use some apps like "SDRescan" to force MTP DB refresh.
If you're looking for sample code, here is:

For System app
MediaScannerConnection.scanFile(this, new String[] { Environment.getExternalStorageDirectory().getAbsolutePath() }, null, null);
For non-system app
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+Environment.getExternalStorageDirectory()))); 
Further discuss, please refer to
http://code.google.com/p/android/issues/detail?id=38282

No comments: