react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Cannot access SDcard (ExternalStorageDirectoryPath points to /storage/emulated/0)

Open Epick362 opened this issue 6 years ago • 15 comments

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.

Epick362 avatar Dec 29 '18 14:12 Epick362

I think you can't modify files on an external SDcard anymore.

nitinkumar24 avatar Jan 06 '19 19:01 nitinkumar24

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?

Epick362 avatar Jan 09 '19 11:01 Epick362

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.

nitinkumar24 avatar Jan 09 '19 12:01 nitinkumar24

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?

Epick362 avatar Jan 10 '19 15:01 Epick362

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 .

nitinkumar24 avatar Jan 10 '19 15:01 nitinkumar24

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 .

nitinkumar24 avatar Jan 10 '19 15:01 nitinkumar24

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 ?

Pruthvirajcodewave avatar May 02 '19 15:05 Pruthvirajcodewave

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

burtek avatar Jun 06 '19 12:06 burtek

same here,any update?

ccksfh avatar Jun 20 '19 08:06 ccksfh

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.

emilioicai avatar Aug 27 '19 10:08 emilioicai

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()

theill avatar Sep 05 '19 20:09 theill

Thankyou @emilioicai RNFS.getAllExternalFilesDirs() worked for me...!

JowelTisso avatar Feb 16 '21 08:02 JowelTisso

Maybe it works adding the following property to the AndroidManifest.xml

<application
  android:requestLegacyExternalStorage="true"

meinto avatar Nov 24 '21 09:11 meinto

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'))));

juanreynolds avatar Feb 23 '22 19:02 juanreynolds

Any update on the SD Card Path. Facing the same issue. ExternalStorageDirectoryPath points to /storage/emulated/0

karanAreksoft avatar Feb 12 '24 16:02 karanAreksoft