My app creates picture files on external storage (/sdcard). I want those images to be viewable from Gallery (not to open them in Gallery, just make viewable if user switches to Gallery). Is there a way to achieve this?
Asked
Active
Viewed 1,478 times
3 Answers
7
Use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); to get the path to the public images directory.
I have never tried to do so, but documentation says that that is the place where the public images (thus the gallery) are located.
EDIT: to notify the gallery DB that another file has been inserted, you might try the following:
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);
}
Source:
-
As a matter of fact, I do put images there by default, and they become visible, but only after device reboot. However, I want to keep the path customizeable. – Violet Giraffe Feb 20 '12 at 11:30
-
Thanks a lot, it works like charm! I've tried something similar before to no avail, but my code had a mistake, as I can see now :) – Violet Giraffe Feb 20 '12 at 15:23
0
I agree with @Jens. Use MediaScannerConnection, particularly the static scanFile() method. See my answer here.