<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<provider
android:name="io.dcloud.common.util.DCloud_FileProvider"
android:authorities="${apk.applicationId}.dc.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/dcloud_file_provider" />
</provider>
上面配置我都添加了 也无法实现plus.runtime.install
下面是的我的代码
/**
- 下载最新应用
/
async function downloadAndInstall(fileId, forceUpdate, fileName) {
let downloadUrl = '';
const result = await http.downloadFileList({
fileIds: [fileId]
});
downloadUrl = result[0].fileUrl;
// console.log('服务端下载结果', downloadUrl)
// #ifdef APP-PLUS
// var showLoading = plus.nativeUI.showWaiting("升级包下载中...");
const dtask = plus.downloader.createDownload(
baseURL + downloadUrl, {
filename: "_doc/update/"
},
(d, status) => {
console.log(d, status)
if (status === 200) {
installWgt(d.filename); // 安装apk包
} else {
//下载失败
plus.nativeUI.closeWaiting(); // 关闭提示弹窗
plus.downloader.clear(); //清除下载任务
plus.nativeUI.alert('版本更新失败:' + status);
}
});
// 监听下载进度
dtask.addEventListener('statechanged', (task) => {
console.log('进度状态', task.state)
switch (task.state) {
case 1: // 开始
showLoading.setTitle("正在下载");
break;
case 2: //已连接到服务器
showLoading.setTitle("已连接到服务器")
break;
case 3: // 已接收到数据
const percent = (task.downloadedSize / task.totalSize) 100;
showLoading.setTitle(" 正在下载" + percent.toFixed(0) + "% ");
break;
case 4: // 下载完成
plus.nativeUI.closeWaiting();
console.log('下载完成')
break;
}
});
dtask.start();
// #endif
}
function installWgt(path) {
// #ifdef APP-PLUS
plus.nativeUI.showWaiting("安装升级文件...");
plus.runtime.install(path, {}, function() {
plus.nativeUI.closeWaiting();
plus.runtime.restart();
}, function(e) {
plus.nativeUI.closeWaiting();
plus.nativeUI.toast("安装wgt文件失败[" + e.code + "]:" + e.message);
});
// #endif
}
0 个回复