I have implemented an application in which I am downloading an image from a url and storing it on an SD card.
It is showing in the emulator gallery after restarting it. Is it possible to show images in a gallery without restarting emulator?
Asked
Active
Viewed 284 times
2

Rahul Gautam
- 4,749
- 2
- 21
- 30

Nitesh Kabra
- 509
- 2
- 9
- 17
-
2What you need exactly..?? Didn't get you clearly... – Lokesh Oct 12 '12 at 10:21
-
I am downloading an image and storing it in SD card. now it should show in gellary also. but its not showing until restart emulator. I want that it should show without restarting emulator. – Nitesh Kabra Oct 12 '12 at 10:25
-
Make use of MediaStore for updating the SDCard media content.. – Kartik Domadiya Oct 12 '12 at 10:35
-
mr kartik will you please elaborate? – Nitesh Kabra Oct 12 '12 at 10:37
1 Answers
2
Approaches:
#1 If you want immediate results then make use of MediaScannerConnection.
MediaScannerConnection.scanFile(ctx,new String[] { path.toString() },null,new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
#2 If you don't need immediate results(eg. you have created new 100s of images) then instead when you are done downloading all the files you could trigger a scan yourself of the entire SD card by telling the system that the card was just mounted:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
Conclusion : If you are writing very small no. of files at a time then make use of #1 otherwise #1 is fast when you are dealing with writing very large no. of files which are to be scanned.

Kartik Domadiya
- 29,868
- 19
- 93
- 104