Forces the Android gallery to refresh its thumbnail images. - Android Graphics

Android examples for Graphics:Bitmap Thumbnail

Description

Forces the Android gallery to refresh its thumbnail images.

Demo Code


//package com.java2s;

import java.io.File;

import android.content.Context;
import android.content.Intent;

import android.net.Uri;
import android.os.Environment;

public class Main {
    /**//from w  w w  .  ja va2s  .c  o m
     * Forces the Android gallery to  refresh its thumbnail images.
     * @param context
     * @param fdelete
     */
    private static void refreshGalleryImages(Context context, File fdelete) {
        try {
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                    Uri.parse("file://"
                            + Environment.getExternalStorageDirectory())));
        } catch (Exception e1) {
            try {
                Intent mediaScanIntent = new Intent(
                        Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri contentUri = Uri.fromFile(fdelete);
                mediaScanIntent.setData(contentUri);
                context.sendBroadcast(mediaScanIntent);
            } catch (Exception e2) {
            }
        }
    }
}

Related Tutorials