react-native-fs
react-native-fs copied to clipboard
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.
I think you can't modify files on an external SDcard anymore.
Thanks for the response @nitinkumar24 . Does this mean API changed on the Android side to disallow this or is this feature just no longer supported in react-native-fs?
Android does not allow. What you can do is copy file from sd card to storage and then perform write operation. Also, don't forget to delete files from storage.
This is what i do, if you find any other workaround please let me know.
I could not find such information about Android disallowing writing/reading to SDcard in their docs. https://developer.android.com/training/data-storage/files Where did you read that this is not allowed anymore?
I read somewhere for sure. Don't know the exact link.
On Thu, Jan 10, 2019, 21:02 Filip Hájek <[email protected] wrote:
I could not find such information about Android disallowing writing/reading to SDcard in their docs. https://developer.android.com/training/data-storage/files Where did you read that this is not allowed anymore?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/itinance/react-native-fs/issues/610#issuecomment-453137733, or mute the thread https://github.com/notifications/unsubscribe-auth/AYJsKBO2skCriDdCXzjHAjY43NXKLJt7ks5vB10igaJpZM4ZkmCy .
Check this link
https://stackoverflow.com/questions/43066117/android-m-write-to-sd-card-permission-denied Let me know if you find something useful. Also there is answer that saying you can't modify files on sd card
On Thu, Jan 10, 2019, 21:07 Nitin Kumar <[email protected] wrote:
I read somewhere for sure. Don't know the exact link.
On Thu, Jan 10, 2019, 21:02 Filip Hájek <[email protected] wrote:
I could not find such information about Android disallowing writing/reading to SDcard in their docs. https://developer.android.com/training/data-storage/files Where did you read that this is not allowed anymore?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/itinance/react-native-fs/issues/610#issuecomment-453137733, or mute the thread https://github.com/notifications/unsubscribe-auth/AYJsKBO2skCriDdCXzjHAjY43NXKLJt7ks5vB10igaJpZM4ZkmCy .
Hi Epick362, were you able to solve this ? Even i have a similar requirement. I am not able to get the path of SD CARD ?
@nitinkumar24 actually, the accepted answer says otherwise. @itinance Any plans for that?
same here,any update?
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.
The constant is calling the method "getExternalStorageDirectory()" in the Android SDK which is deprecated and should not be used. See https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()
Thankyou @emilioicai RNFS.getAllExternalFilesDirs() worked for me...!
Maybe it works adding the following property to the AndroidManifest.xml
<application
android:requestLegacyExternalStorage="true"
One of these mount points will be the sd-card:
const res = (await RNFS.readFile('/proc/mounts')).split('\n'); let mnt_points = _.flatten(res.map(r => r.split(' ') .filter(r => r.startsWith('/') && !r.includes('/mnt/secure') && !r.includes('/mnt/obb'))));
Any update on the SD Card Path. Facing the same issue. ExternalStorageDirectoryPath points to /storage/emulated/0