Thursday, June 7, 2012

android, refresh image thumbnails, or sd card before calling an intent to choose an image, or rescan image folder in gallery

Hello every1...
So I had looked and search and read and....I guess you all know the routine when you're looking for something android related online and how long sometimes it takes for you to find it working as you want it to....


Case:
Your application uses the camera to take a picture.
U then enable the user to go to a gallery preview you have created, and do what ever with the pictures he has just taken.


Situation:
The thumbnail gallery preview does not show the recent photo/s the user has taken.


Solution:
So here is the code I created:
  1. Your camera Activity saves the image file to a specific location.
  2. Then you wish to update the thumbnail gallery db.
  3. The user switches to the gallery preview.
  4. You need to call addImageGallery(file) right after image file has been saved.

Code:

1
2
3
4
5
6
 private void addImageGallery(File file) {
     ContentValues values = new ContentValues();
     values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
     values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
     getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
 }


Hope that was helpfull....
Full code will be sent upon request....
In-joy...