Cannot write to SD card outside of app dir
Hi. Thanks for the plugin. I am having an issue, which I'm assuming is permissions-related. I need to save some data on a physical SD card that persists after the app is removed, so I need to save it outside of the Android/data/com.example/ directory. My app will only ever be installed on one type of device, so I can hard-code the path. I have no trouble writing to the apps' private directory on the card, but if I try to create a directory elsewhere then it fails.
My manifest includes:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
..and checking dynamically shows the permission as available:
const directory = await getSdCardDirectory();
// /mnt/m_external_sd/Android/media/hrp
if (!await RNFS.exists(directory)) {
console.log("doesn't exist", directory);
try {
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.log("Permission OK");
} else {
console.log("Permission failed");
}
if (await RNFS.mkdir(directory)) {
console.log("Directory created", directory);
} else {
console.warn("Could not create", directory);
}
} catch (err) {
console.warn("Create directory error", err);
}
}
This shows "Permission OK", but throws "Error: Directory could not be created"
Can anyone help? Thanks.
Same problem, the first time created the folder successfully, but after I erased the folder this error appear to me everytime.
Same problem, my client wants to save data on device so that app can work in offline mode. For this i need to download large files on device. I was looking if there is a way to save file directly to SD Card. but i did not find any solution for this in this plugin.
no solution yet :D ?
+1
+1
+1