【问题标题】:Delete photo thumbnail in Gallery after manually delete the photo file手动删除照片文件后删除图库中的照片缩略图
【发布时间】:2012-11-12 00:11:01
【问题描述】:
case R.id.menu_delete:
    File photoToDelete = new File(photoPath, photoList[gPosition]);
    photoToDelete.delete();
    checkPhotoFolder();
    galleryAdapter.notifyDataSetChanged();
    Log.d("position", "" + gPosition);
    return true;

我正在使用上述代码手动删除照片文件。但在系统图库中,照片仍然显示空白缩略图。 问题是如何删除照片文件以及图库中的缩略图?

【问题讨论】:

  • 对最新的答案感到抱歉,但我确实解决了这个错误,例如this

标签: android image gallery photo delete-file


【解决方案1】:

试试这个。

getContentResolver().delete(Uri.fromFile(photoToDelete), null, null);

【讨论】:

    【解决方案2】:

    您必须更新存储照片的数据结构(例如列表或数组)。 我猜是photoList。 所以你应该这样做(假设photoList 是一个数组):

    photoList = photoList.asList().remove(gPosition).toArray();
    

    【讨论】:

    • 我的意思是删除Android内置图库中的照片缩略图兄弟。
    • 这个答案与问题无关。
    【解决方案3】:

    尝试调用 MediaScanner 来刷新图库

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

    来自Google's example的代码

    【讨论】:

    • 这项工作仅用于保存新照片,但当它扫描已删除的文件时,它会在系统图库中显示空白缩略图。
    • @chengsokdara 你说得对,我也面临同样的问题。你有什么解决办法吗???
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多