Hi everyone!
I am trying to write a file inside the Android’s storage using the Capacitor FileSystem plugin, but let me put some context here:
I have an Angular App + Capacitor v3 that needs to save a pdf or an image inside the mobile storage, so I am using the plugin to write a file inside the Documents directory, because it is a must to have this file accessible from any application (for instance using a File Explorer).
So, the problem is that I am facing an internal issue in a devices that are using Android 11. According to the documentation of this Capacitor Plugin (here) the Documents directory is not working in Android versions 11 or above.
So, my error is an internal one, and it is the following: FILE_NOTCREATED.
After some research, I saw that it is possible to add a new permission inside the AndroidManifest:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
And after that, if you go to the application permissions and inside the “Files and Media” ones check the option: “Allow management of all files” everything works like a charm.
So, in that case, as a workarround I am allowing the application to access, modify and delete any files that are in the common storage. So, now it is possible to create each file inside the Document directory using the Filesystem plugin.
But of course, to me this approach is not valid cause it is a manual bypass and it must to be transparent for the user.
So, I need to find a valid solution for that, or maybe there is something that I can improve, some questions:
- Is it possible to write a file inside the Android’s storage but in a common path? Maybe I need to create a temporary directory or a intermediate directory… What is the best approach to do that? Because I need to write this file in a location that allows to the user the visibility of this file.
In that case, the External Directory is not an option because all these files are internal to the applications, so they are not visible to the user as media. - Is it possible to select the “Allow management for all the files” permission option inside the modal that asks to the user the Application’s permission?
Because now, the plugin shows the modal but if you click allow it implies that you are setting permissions only for the media fields, not for all.
After some research I see that it is possible to do that opening an intent in order to ask for this specific permission, but of course this is Android native code: (LINK). So, I guess that it is the plugin itself the one that has to offer this option.
Thanks in advance for your support!