3

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.

1 Answers1

0

You did not tell it but this happens to you on Android 11+ devices.

On Android 11+ an app has only access to the files it created itself and media files in public directories.

After reinstall an app is considered a different app.

Use Storage Access Framework ACTION_OPEN_DOCUMENT to let the user pick the files.

blackapps
  • 8,011
  • 2
  • 11
  • 25
  • Thank you for your answer indeed it is well with android 11 I modified the post to add it, I will inquire in this direction – Laura Friess Dec 14 '22 at 12:57