Closed rolinger closed 8 months ago
You're probably better off migrating to a SAF/MediaStore plugin to manage files in external storage. See this for more details. File plugin can still be used for internal storage without limitations, but using file plugin for external storage with Android's scoped storage mechanisms will cause a lot of headaches.
While the deletion scenario you described does seem to be buggy behaviour, it's not something that Cordova can act on unfortunately. That mechanism is likely controlled by Android's libfuse system, which bridges MediaStorage/scoped storage rules into the kernel.
Even if you do manage to workaround this issue, Android's FUSE system was only implemented in Android 11 (API 30), but scoped storage was introduced in Android 10 (API 29). This means that specifically on API 29 devices, accessing external storage via direct file APIs will not work and the only solution to this is to use a plugin that interfaces MediaStore API.
Well, this issue is back ...and its beyond frustrating. My app is compileSDK/targetSDK Android API 33.
My app allows users to download files to public folders created by my app; my app doesn't need access to other files in other folders created by other apps. I managed to have everything working
You can't directly write to:
file:///storage/emulated/0/Download
You can create and write to:file:///storage/emulated/0/Download/SomeFolder
In my case, for organizational purposes, my app is creating and writing to the following folders:
For the record, most or all of the files my app is downloading are office type files (IE: doc,xls,pdf, etc).
This above was all working. Then I deleted app and re-installed and began further testing other components and when I came back to file downloads nothing would work.
I keep getting
Code: 2
- which is a security code, implying my app cannot see and/or create directories created by my app before the delete. That is somewhat expected as Android probably sees the new install as a different app than the one that create the original directories. But when I change the root dir toMyAppName1
- a directory that has never existed in../Download/
i get the sameCode: 2
error.Additionally, I have found:
The problem in both cases is that if I have to if have to check for the root
MyAppName
folder, but if it was manually deleted or the app was reinstalled, I now have to createMyAppName1
- but since there is no way toREAD
the existence ofMyAppName
, I have to just keep looping through until I can create a new one. IfMyAppName1
was used before, then I have to tryMyAppName2
and so forth.Both are quite nasty, I understand reinstalling an app it treats the original folder path as being owned by a different app instance or altogether created by a different app (something they should be able to fix), but #1 is particularly nasty because it is somehow caching the file returning an error code containing "EEXISTS" - when clearly the user has deleted the file and it doesn't exist - and then download the file again using a different file name. I think this one is a bug.