I want user click action delete image and image will be deleted in gallery. How to delete image in gallery from my phone. I have tried all code in this link stackoverflow but still can't delete image in gallery from my device phone android : deleting an image How to delete a file from Gallery in Android? How to delete an image from device in Android programmatically?
Asked
Active
Viewed 287 times
1
-
Show the code you tried. And tell also what you consider to be 'gallery'. Also we see no image. – blackapps Sep 01 '22 at 10:51
-
Find This tutorial can help you . https://www.youtube.com/watch?v=tYB8LuwE0sg https://github.com/snsurajnath/FunGallery – Islam Alshnawey Sep 01 '22 at 13:07
-
@Islam Alshnawey source code github wrong. Can't delete image in gallery – Alex Sep 01 '22 at 13:22
-
@blackapps I have tried all code in this link stackoverflow but still can't delete image in gallery from my device phone https://stackoverflow.com/questions/10716642/android-deleting-an-image https://stackoverflow.com/questions/60523704/how-to-delete-an-image-from-device-in-android-programmatically https://stackoverflow.com/questions/31932434/how-to-delete-a-file-from-gallery-in-android – Alex Sep 01 '22 at 13:26
-
I will not follow your link. You should write a better post to begin with. For instance what has your image to do with the file you wanna delete? – blackapps Sep 01 '22 at 15:55
-
@ blackapps I can get path uri of image in gallery of my phone. And i want delete that image. But i don't know how to delete image from gallery by java of kotlin code – Alex Sep 01 '22 at 16:10
1 Answers
1
Try this:
File fdelete = new File(uri.getPath());
if (fdelete.exists()) {
if (fdelete.delete()) {
System.out.println("file Deleted :" + uri.getPath());
} else {
System.out.println("file not Deleted :" + uri.getPath());
}
}

Emma Waston
- 26
- 1
-
1This code can not delete image from gallery. I have tried and can't delete image – Alex Sep 01 '22 at 10:49
-
1Has nothing to do with gallery. uri.getPath() does not give a file system path so it is useless. Further there is no println in case the file does not exist which it does not. Sorry Emma you did not try this yourself. – blackapps Sep 01 '22 at 10:54
-
1