How can i delete files from DCIM/Camera?

I need to delete files from the DCIM/Camera directory that were created by the camera editor (launched by my app via ActivityStarter).
I tried using File.Delete, FileTools1.delete, and TaifunFile.delete, but the files continue to be present, and no errors are appearing. Does anyone know how to delete files from DCIM/Camera?
Thanks.

If the image files were not created by the app, then you will probably need to use SAF to delete them.

1 Like

This is not true (at least not with the File component):

No Anke. It's true. Dcim/camera is shared and not legacy.
And in any case - you are not answering to my question - how can you delete a file from dcim/camera?

Thank you TIMAI2. I'll try to use SAF

image

1 Like

No, it is not true, as @TIMAI2 has shown as well.

Of course, I answered your question by liking @TIMAI2's post (#2).

Try this - No errors and file remains

Read your post and my answer again:

Is there anything unclear/misunderstood? I do not think so.

My file extension was written before Google introduced scoped storage...
Nowadays you are not able to delete a file, which you do not own like this anymore
You will have to use SAF

Taifun

Thank you Taifun. I'm trying now to use SAF

Is it really necessary to suggest it 3 times before considering it?

I practice this pattern.

I call it Easiest Attempt First.

Dear ABG, this was a normal POLITE response to TAIFUN (as I responded to TIMA2 who was already very precise in his response) and that's it.
Unfortunately SAF requires OpenSingleDocument but I would like to avoid user interference in simply deleting a file. So I'm looking for something else on the Internet and in the meantime I respond politely to people who really wanted to help me.

You've already found these people. How about you listen to them?

Something like this would work for you?

I believe mediastore provides delete api.

Thanks Sunny, I implemented a simple photo editor in my app which avoided security issues and made the user experience easier. But the idea of using the Mediastore delete API seems very interesting. I will keep that in mind. Thank you

Hi Sunny, I checked Mediastore CreateDeleteRequest and it is simpler than OpenSingleDocument in SAF because the user only needs to confirm deletion of the file and not choose it. Perhaps such a possibility could be useful to other developers (maybe as a new SAF feature?) but I wanted to completely avoid user interference in deleting files in the shared directory and this doesn't seem possible. In this case it seems that the only solution is to create a simple photo editor within my APP and not launch an external photo editor. Thank you. Alex

Yes, there is no solution if your app doesn't own the image.
Even Google's own photos app can't delete images without user interaction in Android 13.

1 Like