【发布时间】:2021-11-06 08:53:16
【问题描述】:
downloadFile = async (url) => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'Storage Permission',
message: 'App needs access to memory to download the file ',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Permission Granted")
let dirs = RNFetchBlob.fs.dirs.MainBundleDir;
const execute = await RNFS.mkdir(`${dirs}/Jharkhand Update Database`)
console.log(execute)
console.log(dirs);
} else {
ToastAndroid.showWithGravity(
'You need to give storage permission to download the file',
ToastAndroid.SHORT,
ToastAndroid.BOTTOM,
);
}
} catch (err) {
console.log('Random ', err);
}
};
无法在 android 11 中创建文件夹。尝试使用 DocumentDir 和 SDCardApplicationDir 代替 MainBundleDir,但没有用。创建一个文件夹很重要,因为我们正在存储管理员发送的消息列表,这样即使移动数据关闭,应用程序仍然可以访问。
【问题讨论】:
标签: reactjs react-native android-11 react-native-fs react-native-fetch-blob