I am using react-native-fs to build a media player like app but I am unable to access directories outside my project folder, I have added these permissions :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
I am also checking the read and write permission using the following code :
PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
).then(granted => {
if (!granted) {
PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
]).then(result => {
console.log(result);
});
}
});
RNFS.readDir() is throwing null error :
const path = RNFS.ExternalStorageDirectoryPath;
RNFS.readDir(path).then(result => {
console.log('GOT RESULT', result);
});
The error that is thrown is :
[Error: Attempt to get length of null array]
CodePudding user response:
Please check / try the following
- Allow storage permissions for the app from the device setting.
- Try update manifest like below by adding
android:requestLegacyExternalStorage="true"
<manifest ... >
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>