Question

I'm building a Camera application and after taking a picture(after writing to a file in the PictureCallback), I want to update the media files on the device and so I use MediaScannerConnection(as in the following code). But, I'm not able to view the images in the gallery application on the device. However I can view the images on the PC(The images are on the SD card). Am I missing anything?

MediaScannerConnection.scanFile(this, new String[] {pictureFile.toString()}, null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.d("ExternalStorage", "Scanned " + path + ":");
Log.d("ExternalStorage", "-> uri=" + uri);
}
});

Was it helpful?

Solution

I think the following might be helpful (from the android-developers mailing list archive):

Oh man.. after 3 days of searching and bothering a couple people ive finally found the solution.. this one line of code:

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

thats it.. it sends an intent on which the mediascanner starts itself, and voila, the whole external storage searched for media.. find new items, deletes the ones that dont exist anymore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top