0

I want to know how to refresh the gallery after deleting list of images.I am using the following method for deleting and refreshing.

    public static void deleteFile(Context context,String path) {

        File file = new File(path);
        String abspath = file.getAbsolutePath();
        File f = new File(abspath);
        if (f.exists()) {
            if (f.delete()) {

                deleteFileFromMediaStore(context.getContentResolver(),f);

            } else {
                CommonlyUsed.logmsg(" file not deleted " + (cnt++));
            }
        }

public static void deleteFileFromMediaStore(final ContentResolver contentResolver, final File file) {
    String canonicalPath;
    try {
        canonicalPath = file.getCanonicalPath();
    } catch (IOException e) {
        canonicalPath = file.getAbsolutePath();
    }
    final Uri uri = MediaStore.Files.getContentUri("external");
    final int result = contentResolver.delete(uri,MediaStore.Files.FileColumns.DATA + "=?", new String[] {canonicalPath});
    if (result == 0) {
        final String absolutePath = file.getAbsolutePath();
        if (!absolutePath.equals(canonicalPath)) {
            contentResolver.delete(uri,MediaStore.Files.FileColumns.DATA + "=?", new String[]{absolutePath});
        }
    }
}

but it take more time for deleting and refreshing around 8000 images. which is the better way to delete and refresh.

  • Possible duplicate of [How to refresh Gallery after deleting image from SDCard](http://stackoverflow.com/questions/22606080/how-to-refresh-gallery-after-deleting-image-from-sdcard) – Mahesh Giri May 04 '16 at 13:43
  • In the case you want to get notified if medias got changed, deleted or inserted from outside or within inside your app >> http://stackoverflow.com/a/38569032/2123400 – Eftekhari Aug 09 '16 at 18:20

0 Answers0