1

Images moved by Tasker persist in MediaStore

Hi!

I am writing an app that downloads images into an folder. I was using Tasker to move and combine files from multiple folders into one folder. However, I saw that my app crashes when I re-download an image, that I downloaded before and then moved with tasker.

contentResolver.insert gives me: SQLiteConstraintException: UNIQUE constraint failed: files._data where _data is the path of the by then non-existent file, and I need to use contentResolver.delete to delete the empty row from the MediaStore, after that I can download the file.

Now, I was investigating this issue and found that if I use other apps to move these files manually (Solid Explorer, Simple Gallery, and others) this issue is not present and I can download the same file again after moving it out of the folder without the need to delete an entry from the MediaStore. The fact, that these files are still present in the MediaStore is also shown going into the Android files app > Images. Moved/later deleted files are still shown, without a thumbnail and with no picture if you click on them.

This leads me to the thinking that maybe the way how Tasker moves files is not on par with the requirements of the system (MediaStore, contentResolver)?, as Android 10 introduced Scoped Storage; Android 11 making at mandatory

I attach both the task and the code I used, maybe you can get an idea of my issue, but maybe it's also an error on my side.