Cordova插件后台下载失败

问题描述 投票:0回答:2

我需要使用我的 Cordova 应用程序下载大文件(160GB)。由于文件传输插件已被弃用,并且建议 XMLHTTPRequest 使用因巨大失败而失败,我从 https://github.com/sgrebnov/cordova-plugin-background-download 下载了 cordova-plugin-background-download 。它适用于任何 iOS 设备,但在 Android 13 上总是失败并出现错误

Unsupported path /storage/emulated/0/ ......

该错误是在创建临时文件时发生的。我认为问题出在这段代码上:

this.setTempFileUri(Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory().getPath(),
                Uri.parse(targetFileUri).getLastPathSegment() + "." + System.currentTimeMillis())).toString());

哪里

android.os.Environment.getExternalStorageDirectory().getPath()

返回无效路径。

有没有解决方法,如何让插件在 Android 13 上运行?我使用 Github 上插件主页的示例代码。

android file cordova download
2个回答
0
投票

需要修改 src/android/BackgroundDownload.java 文件的第 114 行以获得正确的功能

this.setTempFileUri(Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory().getPath(),
Uri.parse(targetFileUri).getLastPathSegment() + "." + System.currentTimeMillis())).toString());

this.setTempFileUri(Uri.fromFile(new File(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS),
Uri.parse(targetFileUri).getLastPathSegment() + "." + System.currentTimeMillis())).toString());

-1
投票

您可以使用此代码吗?

© www.soinside.com 2019 - 2024. All rights reserved.