Currently I'm dealing with file downloading function of react-native app.
What I'm wondering is how can I show 'Download completed' notification as shown in the image right after the file has downloaded at notification center.
RN Version : 0.61.5
Currently I'm dealing with file downloading function of react-native app.
What I'm wondering is how can I show 'Download completed' notification as shown in the image right after the file has downloaded at notification center.
RN Version : 0.61.5
according to https://github.com/cjdell/react-native-fs-test/blob/master/index.common.js
const ret = RNFS.downloadFile({ fromUrl: url, toFile: downloadDest });
ret.promise.then(res => {
// Show Your Notification
}).catch(err => {});
for notification you can use https://github.com/zo0r/react-native-push-notification, this is an example:
RNFS.downloadFile({
fromUrl,
toFile,
}).promise.then((res) => {
PushNotification.localNotification(details)
});
You can use RNFetchBlob package to download any file from the internet and configure the options to show notification, set notification : true, to get the status of download whether complete or ongoing, (only Android), if you keep it false you need to add one more permission in the manifest, i.e DOWNLOAD_WITHOUT_NOTIFICATION
let options = {
fileCache: true,
addAndroidDownloads : {
useDownloadManager : true,
notification : false,
path: PictureDir + "/image_"+Math.floor(date.getTime() + date.getSeconds() / 2)+".png",
description : 'Image'
}
}
config(options).fetch('GET', url)
I used RNFetchBlob to download image/pdf. This helped me to show download notification.
RNFetchBlob.android.addCompleteDownload({
title: "QR Code Image",
description: 'Download complete',
mime: 'image/png',
path: path,
showNotification: true,
})
for me its image file so mime type is "image/png" for pdf its "application/pdf"