wap2app打包的Android应用,本身是给予webrtc的文件传输应用,但是打包出来的软件无法下载东西,提示下载失败。储存权限是有的。

NoverNobida
- 发布:2020-07-02 00:43
- 更新:2025-08-18 16:39
- 阅读:1890

发现可以用html5+ 下载文件
const downloadFile = (list) => {
plus.android.requestPermissions(['android.permission.WRITE_EXTERNALSTORAGE'], () => {
const fileUrl = 'https://example.com/file.pdf';
const saveDir = 'file://storage/emulated/0/MyAppDownloads/';
const filename = `file${Date.now()}.pdf`;
const savePath = saveDir + filename;
// 创建目录(若不存在)
const File = plus.android.importClass('java.io.File');
const dir = new File(plus.io.convertLocalFileSystemURL(saveDir));
if (!dir.exists()) dir.mkdirs();
// 开始下载
const dtask = plus.downloader.createDownload(
fileUrl,
{ filename: savePath },
(d, status) => {
if (status === 200) {
const localPath = plus.io.convertLocalFileSystemURL(d.filename);
uni.showToast({ title: '下载成功' });
plus.runtime.openFile(localPath); // 打开文件
} else {
uni.showToast({ title: '下载失败', icon: 'error' });
}
}
);
dtask.start();
});
}
NoverNobida (作者)
不是这个意思,不是打包的软件下载不下来,是指软件使用中,这个软件要下载东西,下载失败。是基于webrtc的p2p传输软件,一个文件传输小工具。
2020-07-04 20:49