Hello everyone
Environment :
- Android 11
- react-native 0.68.5
- react-native-fs 2.20.0
Need:
Save files persistent to the application (if I uninstall the application the files need to persist). If I reinstall the application I need to be able to manipulate these files again. I uploaded the files in the download folder with RNFS.DownloadDirectoryPath
so that they are not deleted when the application is uninstalled but the files are public and can be downloaded to another location if needed.
Error:
Everything works perfectly until I uninstall and reinstall the application. As soon as I want to manipulate an existing file in my /storage/emulated/0/Download/AppName/...
I encounter the following error when I want to move file :
Error: ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/AppName/...
I encounter the following error when I want to download file :
Error: ENOENT: no such file or directory, open '/storage/emulated/0/Download
Before manipulating a file I make sure I have the :
- PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
- PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
My build.gradle :
buildToolsVersion = "31.0.0"
minSdkVersion = 30
compileSdkVersion = 31
targetSdkVersion = 31
My manifest :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
....
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
...
A big thank you to the people who will take their time to help me
To try to solve the problem I added this line in my manifest :
android:preserveLegacyExternalStorage="true"
and I changed the minSdkVersion
in my build.gradle
from 21 to 30.
I have the impression that the rights belonged to the application as if by reinstalling the application it lost its rights.