I'm trying to copy a file called "contactos.txt" from the Download folder to the Application Specific Directory using Taifum File Extension, but it's giving a permission error. I tried "Read_External_Storage" and "Write_External_Storage", but nothing worked.
Error message:
'file:/storage/emulated/0/Android/data/appinventor.ai_ugmcp_somincor.ContactosSomincor/files: open failed: ENOENT (No such file or directory)'.
Thanks! I Also had to include the file name in "dirpath":
so dirpath is now:
/storage/emulated/0/Android/data/appinventor.ai_ugmcp_somincor.ContactosSomincor/files/contactos.txt
The error message is:
'Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{95a49dd 24119:appinventor.ai_ugmcp_somincor.ContactosSomincor/u0a205} (pid=24119, uid=10205) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs'.
So on first run of the app, get the user to go off and pick the file, TakePersistableUriPermission for the contenturi, then store the contenturi for subsequent use. Have a check in place if the automatic method fails, so that the user can go off and pick the file again.
As said above not sure what happens when the original file is updated/replaced, you will need to test this (and please report back)
If the user has done this once at the beginning, he already has full access to the file and can of course, as I have shown, copy it to one of the Shared folders or the ASD. After that, the app has full access to this file without any permissions, since it created this file itself.
These statements (regarding the Shared folder) of course only apply to Android 11+.
We have perhaps not yet asked the right question. Where does this text file come from, and how does it get onto a users device. Is it created/updated by another app?