删除android中的图像列表后如何刷新图库?

时间:2016-05-04 12:41:40

标签: android image gallery delete-file

我想知道在删除图像列表后如何刷新图库。我使用以下方法进行删除和刷新。

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

但删除和刷新大约8000张图片需要更多时间。这是删除和刷新的更好方法。

0 个答案:

没有答案