Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh Gallery after deleting image from SDCard

When deleting the images on Android’s SD Card, sometimes the images are correctly removed but in the gallery still remains a preview of the removed image. When tapping on it, it is loaded as a black image. To resolve it I need to run MediaScanner. But this code doesn't work and still, the preview of review image remains in the Gallery.

Anyone knows how to resolve this.

Uri contentUri = Uri.fromFile(file);
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri); 
sendBroadcast(mediaScanIntent);
like image 926
AndroidDev Avatar asked Mar 24 '14 09:03

AndroidDev


People also ask

How do I refresh my gallery?

Try going to Settings>SD card & phone storage>Unmount Sd card>Mount SD card. That should trigger the media scanner, and your gallery should refresh.

Why is it when I delete pics from my device they also delete from my SD card?

Internal storage with dcim camera map doesn't contain any images. Therefore the only option which remains is to delete images from the picture map which automatically deletes all images saved on sd as well. Actually the device stores images on both storages and deletes from both.

How do you delete photos that Cannot be deleted?

Go to “Settings” > “Accounts” > “Google“. From there, you can select the Google account you are using, then uncheck the “Sync Picasa Web Albums” option. Now under “Settings” > “Application manager“, swipe over to “All” > “Gallery“, and select “Clear data“.

Why can't I delete photos from Samsung gallery?

Restart Your Device This is a very simple step but believe it or not, in case you can't delete photos from your Android gallery, after a simple restart, you might just be able to. Restarting the phone helps get rid of temporary files and app cache that can often interfere with the operations of your Android smartphone.


1 Answers

For each file while deleted use this

KITKAT

this worked for me

try {
            context.getContentResolver().delete(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    MediaStore.Images.Media.DATA + "='"
                            + new File(fileUri).getPath() + "'", null);
        } catch (Exception e) {
            e.printStackTrace();

        }
like image 186
user2582324 Avatar answered Sep 19 '22 20:09

user2582324