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);
}
};
Unable to create a folder in android 11. Tried using DocumentDir & SDCardApplicationDir in place of MainBundleDir as well but of no use. It is important to create a folder as we are storing a list of messages which are being sent by the admin so that the app remains accessible even if the mobile data is switched off.
Android 11+ needs the permission
MANAGE_EXTERNAL_STORAGEalongside withWRITE_EXTERNAL_STORAGEfor any file management to work as itended.Don't forget to add
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />andandroid:requestLegacyExternalStorage="true"on yourmanifest.xmlfileRead more about it here and here