下载管理器使用 rn-fetch-blob 给出错误代码 16

发布于 2025-01-19 19:12:22 字数 1126 浏览 1 评论 0原文

下载管理器使用 rn-fetch-blob 给出错误代码 16。如果我使用 Android 下载管理器。如果不这样做,请使用 Android 下载管理器,然后应用程序就会崩溃。

android版本:11。

代码:

let dirs = RNFetchBlob.fs.dirs;
RNFetchBlob
.config({
  addAndroidDownloads : {
    useDownloadManager : true,
    notification : true,
    mime : 'image/*',
    mediaScannable : true,
    description : 'File downloaded by download manager.',
    path : dirs.DownloadDir + '/' + fileName,
    overwrite: true,
    fileCache: true,
  },
})
.fetch('GET', FILE_URL, {
  Authorization: `Bearer ${token}`,
})
.then((res) => {
  console.log('The file saved to ', res.path())
})

在manifest.xml中设置以下:

<application android:requestLegacyExternalStorage="true" ... />

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

如果有人可以为我提供解决方案,请。

download manager gives error code 16 with rn-fetch-blob. If I use the android download manager. If I don't, use the android download manager, then the app crashes.

android version: 11.

Code:

let dirs = RNFetchBlob.fs.dirs;
RNFetchBlob
.config({
  addAndroidDownloads : {
    useDownloadManager : true,
    notification : true,
    mime : 'image/*',
    mediaScannable : true,
    description : 'File downloaded by download manager.',
    path : dirs.DownloadDir + '/' + fileName,
    overwrite: true,
    fileCache: true,
  },
})
.fetch('GET', FILE_URL, {
  Authorization: `Bearer ${token}`,
})
.then((res) => {
  console.log('The file saved to ', res.path())
})

Following are set in manifest.xml:

<application android:requestLegacyExternalStorage="true" ... />

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

Please if anyone can provide me with a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔少女心 2025-01-26 19:12:22

根据他们的 自述,您需要在使用下载管理器时添加 DOWNLOAD_COMPLETE 操作。

Also, if you're going to use Android Download Manager you have to add this to AndroidManifest.xml

    <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
+           <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
    </intent-filter>

另外,当需要的调用缺少身份验证标头时,我遇到了错误代码 16。

According to their readme, you need to add the DOWNLOAD_COMPLETE action when using the download manager.

Also, if you're going to use Android Download Manager you have to add this to AndroidManifest.xml

    <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
+           <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
    </intent-filter>

Also, I've been facing the error code 16 when the Authentication header was missing for a call that needed one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文