Reputation: 3189
I'm stuck so I hope someone can help :) I have an activity where I can load the image from gallery and then it shows on the screen. On that screen I have an option to delete that image. When I choose the option to delete the image, image is successfully deleted but it still shows in the gallery when I choose to load another image. So, user can still select old picture from gallery but in this case it doesn't show up on screen because it's deleted. How to refresh the gallery after the picture is deleted?
I've tried this but it seems it doesn't work:
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
I want to avoid scanning SD card manually every time when I delete some image.
Upvotes: 1
Views: 4342
Reputation: 41
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
I use the code above in froyo and the result that code works fine in froyo.
Upvotes: 4
Reputation: 3189
The problem was that i was passing image URI instead of absolute path when deleting so it was unsuccessful. The code should look like this.
File file = new File("some URI I received as a result of one method")
path = file.getAbsolutePath();
File f = new File(path);
if (f.exists()) {
if (f.delete()) {
Log.w("DELETED","file Deleted");
} else {
Log.w("NOT DELETED","file not Deleted");
}
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
imageViewField.setImageBitmap(null);
So, that method works but file was not deleted at all so it was still in the gallery.
Upvotes: 0