Delete an image by content URI

from the CommonsWare Community archives

At March 29, 2020, 2:16pm, sudokai asked:

Hi,

I’m taking a picture with the camera and saving it. In Android Q and above, I use the context.contentResolver.insert function to get a content Uri and for Android versions below Q, I create the file on disk and then use FileProvider to get the Uri. In both cases, I pass that Uri as the MediaStore.EXTRA_OUTPUT of the MediaStore.ACTION_IMAGE_CAPTURE intent and that Uri is also what I save in my database.

If later, I want to delete the picture, how am I supposed to do that by Uri? In StackOverflow, everyone is doing it in a different manner and at this point, I don’t know what works and what not and for which Android versions.


At March 29, 2020, 2:55pm, mmurphy replied:

I have no idea, to be honest. My understanding is that delete() for a MediaStore Uri deletes the MediaStore entry, not any underlying content.

Personally, if I were writing an app that put the content out in a common directory (e.g., Pictures/), then I would consider deleting that picture to be the user’s responsibility, not the app’s. The point behind putting it in that common area is so that it is clearly the user’s content, not the app’s, and so the app has no more responsibility for that content.