update Gallery with MediaScannerConnection - Android android.media

Android examples for android.media:Media

Description

update Gallery with MediaScannerConnection

Demo Code

import android.content.Context;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;

public class Main {

  public static void updateGallery(final Context context, String filename) {
    MediaScannerConnection.scanFile(context, new String[] { filename }, null,
        new MediaScannerConnection.OnScanCompletedListener() {
          public void onScanCompleted(String path, Uri uri) {
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));

          }/*w ww .  j  a v a 2s  .  c  om*/
        });
  }

}

Related Tutorials