Skip to main content
Participant
Sep 6, 2011 1:11 PM UTC
Question

[android]way to refresh gallery after saving image?

I'm saving image to a separate folder on SD card using "File" class. Image is saved correctly but the problem is, it does not appear automatically in the phone's gallery. It appear only after the SD card is rescaned for example when I'm disconnecting my phone form computer. Is there any way to rescan images folder automatically? I've read there is a MediaScannerConnection class in android java which does it. How about AIR?

This topic is closed to new replies. Start a new post to keep the conversation going.

23 replies

Participant
Oct 1, 2011 12:04 PM UTC

If you can use Air 3.0, create a native extension, and call this code (in Java)

taken from: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.html

    // Tell the media scanner about the new file so that it is

    // immediately available to the user.

    MediaScannerConnection.scanFile(this,new String[] { file.toString() }, null,

    new MediaScannerConnection.OnScanCompletedListener() {

    public void onScanCompleted(String path, Uri uri) {

    Log.i("ExternalStorage", "Scanned " + path + ":");

    Log.i("ExternalStorage", "-> uri=" + uri);

    }

    });

Translate
Participating Frequently
Mar 14, 2012 2:22 AM UTC

Thanks for the hint, I've create a simple native extension for refreshing Android gallery.

The ANE file can be downloaded from here, with detailed usage on my blog post.

Translate
Known Participant
Jul 11, 2012 8:51 PM UTC

Thanks, I've used your ANE

Translate
Inspiring
Sep 7, 2011 4:27 PM UTC

You might need to wait AIR 3.0. You will probably need a native extension for AIR that will use that java API.

Translate
Sep 6, 2011 9:52 PM UTC

Im not sure exactly how to implement it without seeing your code, but im sure you can do this using a timer, witha update interval. Google it, look into timers.

Translate
Participant
Sep 7, 2011 7:30 AM UTC

I think you don't get what I mean. This has nothing to do with timers. The problem is that after closing my app I can't see the files it has created. This can be image or sound.

When I plug in my SD card to computer I can see this files - they are there!

On phone I can see them after SD card is rescaned (on my HTC desire this happens after unplugging phone from PC).

Translate
Sep 7, 2011 3:32 PM UTC

Oh I apligize, Then I am unsure of how to fix this. Maybe its to do with the HTC, or your testing whilst plugged into the PC, im not sure.

Hope you find your answer.

Translate