Android 手动删除照片文件后删除库中的照片缩略图
我正在使用上述代码手动删除照片文件。但是在系统库中,照片仍然显示空白缩略图。Android 手动删除照片文件后删除库中的照片缩略图,android,image,gallery,photo,delete-file,Android,Image,Gallery,Photo,Delete File,我正在使用上述代码手动删除照片文件。但是在系统库中,照片仍然显示空白缩略图。 问题是如何删除图片库中的照片文件及其缩略图?您必须更新存储照片的数据结构(如列表或数组)。 我猜是照片列表。 所以您应该这样做(假设photoList是一个数组): 尝试调用MediaScanner刷新库 photoList = photoList.asList().remove(gPosition).toArray(); 来自的代码试试这个 // Tell the media scanner about the n
问题是如何删除图片库中的照片文件及其缩略图?您必须更新存储照片的数据结构(如列表或数组)。 我猜是
照片列表
。
所以您应该这样做(假设photoList
是一个数组):
尝试调用MediaScanner刷新库
photoList = photoList.asList().remove(gPosition).toArray();
来自的代码试试这个
// 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);
}
});
我的意思是删除Android内置gallery bro中的照片缩略图。此答案与问题无关。此操作仅用于保存新照片,但当它扫描已删除的文件时,系统gallery中会显示一个空白缩略图。@chengsokdara你是对的,我面临相同的问题。你们有什么解决办法吗???很抱歉最近的答案,但我确实解决了这个错误
// 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);
}
});
getContentResolver().delete(Uri.fromFile(photoToDelete), null, null);