问题
case R.id.menu_delete:
File photoToDelete = new File(photoPath, photoList[gPosition]);
photoToDelete.delete();
checkPhotoFolder();
galleryAdapter.notifyDataSetChanged();
Log.d("position", "" + gPosition);
return true;
I'm manually delete a photo file using above code. But in the system gallery the photo still show the blank thumbnail. The question is how can I delete the photo file and also the thumbnail of it in the gallery?
回答1:
Try invoke the MediaScanner to refresh the gallery
// 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);
}
});
Code from Google's example
回答2:
Try this.
getContentResolver().delete(Uri.fromFile(photoToDelete), null, null);
回答3:
You must update the data structure (eg. list or array) that stores the photos.
I guess it is photoList
.
So you should do (assuming photoList
is an array):
photoList = photoList.asList().remove(gPosition).toArray();
来源:https://stackoverflow.com/questions/13532285/delete-photo-thumbnail-in-gallery-after-manually-delete-the-photo-file