Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image, saved to sdcard, doesn't appear in Android's Gallery app

I save an image to the sdcard and it doesn't appear in the Gallery application until I pull off the sdcard and return it back.

Do you have any idea why is it so?

Seems like the Gallery application has some cache that isn't updated on file save...

Actually, I also want to open the just-saved image in Gallery application and have no success with that
this is my question about this issue.

like image 813
Michael Kessler Avatar asked Jan 31 '10 01:01

Michael Kessler


People also ask

Why are my SD card photos not showing up in gallery?

If the SD card files are not showing up in Gallery on your Android phone but appear on your computer, your memory card may have a file system that your mobile is incompatible with. Android doesn't support NTFS file system. Instead, it is fully compatible with FAT32, Ext3, and Ext4 file system.

Why images are not showing in gallery?

Delete all .Open Media Rescan app » tick All media checkbox » and hit the Start Media Scan button. Once all media files are rescanned, open the Gallery app. All your media files should be visible on your device now.

Why some photos are not showing in gallery Android?

If your photos are visible in My Files but are not in the Gallery app, these files may be set as hidden. This prevents Gallery and other apps from scanning for media. To solve this, you can change the option for showing hidden files.


3 Answers

A simpler solution is to use the static convenience method scanFile():

File imageFile = ... MediaScannerConnection.scanFile(this, new String[] { imageFile.getPath() }, new String[] { "image/jpeg" }, null); 

where this is your activity (or whatever context), the mime-type is only necessary if you are using non-standard file extensions and the null is for the optional callback (which we don't need for such a simple case).

like image 166
darrenp Avatar answered Oct 10 '22 11:10

darrenp


My answer to the original question and to anyone else that may have this problem:

I was having this same problem, images in my app that people saved to the SD card were not showing up in their Gallery immediately. After some searching I found this one line of code inserted after my 'save to sdcard' code that fixed the problem:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
like image 37
ShadowGod Avatar answered Oct 10 '22 10:10

ShadowGod


The system scans the SD card when it is mounted to find any new image (and other) files. If you are programmatically adding a file, then you can use this class:

http://developer.android.com/reference/android/media/MediaScannerConnection.html

like image 29
hackbod Avatar answered Oct 10 '22 11:10

hackbod