Namratha
Namratha

Reputation: 16790

Updating gallery after taking pictures android Camera application failing

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);
}
});

Upvotes: 0

Views: 1433

Answers (1)

himanshu
himanshu

Reputation: 1980

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.

Upvotes: 8

Related Questions