react-native-fs: Cannot access SDcard (ExternalStorageDirectoryPath points to /storage/emulated/0)

Hello, I am trying to access and modify files on an external SDcard on Android Marshmallow 6.0.1 (SDK 22) In AndroidManifest.xml I have declared following permissions:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

When I print RNFS.ExternalStorageDirectoryPath I can only get an emulated path (/storage/emulated/0) which is not on the SDcard.

I think this is most likely some permissions issue but I have checked everything: app permissions in settings which have storage enabled and also when I check the storage permissions dynamically using this code

    const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
            title: "Grant SD card access",
            message: "We need access"
        }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        console.warn("Permission OK");
    }

It works as expected so I am really out of ideas. Is there anything I might be missing or is this a bug with the library? Thank you for any help with this.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 5
  • Comments: 15

Most upvoted comments

ExternalStorageDirectoryPath might point to the shared storage folder in the internal memory. You should rather check RNFS.getAllExternalFilesDirs() and use one of the dirs listed there as it will show not only the shared space but also any SDCards.

@nitinkumar24 actually, the accepted answer says otherwise. @itinance Any plans for that?