Is there any way to show 'download completed' notification using react-native?

Viewed 3467

enter image description here

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

3 Answers

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"

Related