我正在使用react native fs构建一个类似媒体播放器的应用程序,但我无法访问项目文件夹之外的目录,我添加了以下权限:
<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" />
我还使用以下代码检查读写权限:
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((正在引发null错误:
const path = RNFS.ExternalStorageDirectoryPath;
RNFS.readDir(path).then(result => {
console.log('GOT RESULT', result);
});
抛出的错误是:
[Error: Attempt to get length of null array]
请检查/尝试以下
- 允许设备设置中应用程序的存储权限
- 尝试通过添加
android:requestLegacyExternalStorage="true"
来更新清单,如下所示
<manifest ... >
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>