I have a problem trying to get MediaScanner to scan just one directory.
My app takes pictures, and saves them to sd-card/DCIM/AppPictures/, and obviously I need to invoke the MediaScanner for them to show up in the gallery app. The following code DOES work for my purpose:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
But it just seems so wasteful! I don't want to use resources trying to scan the whole SDcard when I know exactly where the files are. I have tried the following too:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory+"/DCIM/AppPictures/")));
But this fails to yield any results. Can someone PLEASE let me know the proper way to get this done?
public static void ScanMyFile(String strFilePath) {
// Tell the media scanner so it is available to the user.
MediaScannerConnection.scanFile(null, new String[] { strFilePath }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With