有什么方法可以使用 react-native 显示 'download completed' 通知吗?

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

目前正在处理react-native app的文件下载功能

我想知道如何在通知中心下载文件后立即显示 'Download completed' 通知,如图所示。

RN 版本:0.61.5

根据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 => {});

您可以使用 https://github.com/zo0r/react-native-push-notification 进行通知,这是一个示例:

RNFS.downloadFile({
    fromUrl,
    toFile,
}).promise.then((res) => {
    PushNotification.localNotification(details)
});

您可以使用 RNFetchBlob 包从 Internet 下载任何文件并配置显示通知的选项,设置通知:true,以获取下载状态是完成还是正在进行,(仅限 Android),如果你保持错误,你需要在清单中再添加一个权限,即 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)

我使用 RNFetchBlob 下载 image/pdf。这有助于我显示下载通知。

RNFetchBlob.android.addCompleteDownload({
                title: "QR Code Image",
                description: 'Download complete',
                mime: 'image/png',
                path: path,
                showNotification: true,
              })

对我来说它的图像文件所以 mime 类型是“image/png”对于 pdf 来说它是“application/pdf”