I’m trying to create a new JSON file generated by my Flutter application and I wanna let the user to choose where to store this file.
I’m currently using file_picker
package to let the user to choose the path to store the generated file. If I select the Documents folder (/storage/emulated/0/Documents
) I can create that file, but if I choose another path (like /storage/emulated/0/DCIM
or a custom folder created by the user named Test
for example) I get the following exception:
FileSystemException: Cannot open file, path = '/storage/emulated/0/Test/backup.json' (OS Error: Operation not permitted, errno = 1)
Note that I’m running my app on an emulator that have Android 13. I also tried to add this permissions in the Manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
And tried to request storage permissions with the package permission_handler
but nothing change.
2
Answers
DCIM maybe is part from media or photos
so try this if work, I do usually include in my manifest
and setting my gradle as like this
then for permission you can either put them on list just in case when requesting
If you are targeting Android 11 and up(targetSdkVersion 30) then you require the following permissions in AndroidManifest.xml for modifying and document access.
You can find more details in here
https://stackoverflow.com/a/66366102/19292778