0

我有以下代码可以从我创建的下载文件夹中取消链接/删除文件,也可以使用相同的路径通过应用程序创建。

注意我使用的是 RNFetchBlob 包。

---
const fs = RNFetchBlob.fs
const base64 = RNFetchBlob.base64
const dirs = RNFetchBlob.fs.dirs

RNFetchBlob.fs
      .unlink(dirs.DownloadDir + '/passpoint.config.xml')
      .then(() => {
        alert("File deleted");
      })
      .catch(err => {
        alert(err);
      });
---

我不断收到以下错误;

[Error: Failed to delete '/storage/emulated/0/Download/passpoint.config.xml']

我认为它可能是路径,但这与我用来创建文件的路径相同,我可以通过 Android 上的文件资源管理器查看该文件。

解决方案

fs.unlink(dirs.DownloadDir + '/passpoint.config.xml');
4

2 回答 2

0

使用MANAGE_EXTERNAL_STORAGE权限作为快速解决方案(编辑AndroidManifiest.xml

https://developer.android.com/training/data-storage/manage-all-files

或者使用更高级的技术:

https://developer.android.com/training/data-storage/shared/media

https://developer.android.com/training/data-storage/shared/documents-files

于 2021-07-18T11:15:37.587 回答
-1

只需添加android:requestLegacyExternalStorage="true"AndroidManifiest.xml 文件

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true">
于 2021-06-18T11:51:54.643 回答