3
case R.id.menu_delete:
    File photoToDelete = new File(photoPath, photoList[gPosition]);
    photoToDelete.delete();
    checkPhotoFolder();
    galleryAdapter.notifyDataSetChanged();
    Log.d("position", "" + gPosition);
    return true;

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

4

3 回答 3

0

尝试调用 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 示例的代码

于 2012-11-23T16:00:11.910 回答
0

尝试这个。

getContentResolver().delete(Uri.fromFile(photoToDelete), null, null);
于 2015-08-24T16:48:20.690 回答
-1

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

photoList = photoList.asList().remove(gPosition).toArray();
于 2012-11-23T15:59:00.537 回答