Skip to main content
Participant
September 6, 2011
Question

[android]way to refresh gallery after saving image?

  • September 6, 2011
  • 3 replies
  • 10657 views

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 has been closed for replies.

3 replies

Participant
October 1, 2011

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);

    }

    });

Participating Frequently
March 14, 2012

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.

Known Participant
July 11, 2012

Thanks, I've used your ANE

Inspiring
September 7, 2011

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

September 6, 2011

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.

Participant
September 7, 2011

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).

September 7, 2011

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.