【发布时间】:2016-11-14 06:31:41
【问题描述】:
我使用此代码从我的本地主机下载 apk
function downloadApkAndroid(data) {
var fileURL = "cdvfile://localhost/persistent/path/to/Download/";
var fileTransfer = new FileTransfer();
var uri = encodeURI(data);
fileTransfer.download(
uri,
fileURL,
function (entry) {
console.log("download complete: " + entry.fullPath);
promptForUpdateAndroid(entry);
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
}
);
}
我下载成功然后它会调用这个函数promptForUpdateAndroid(entry);来尝试安装它包含这个函数的函数
function promptForUpdateAndroid(entry) {
console.log(entry);
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: entry.toURL(),
type: 'application/vnd.android.package-archive'
},
function () {
},
function () {
alert('Failed to open URL via Android Intent.');
console.log("Failed to open URL via Android Intent. URL: " + entry.fullPath);
}
);
}
在它调用该函数后我得到了警报
解析错误 - 解析包时出现问题
我认为 fileURL var fileURL = "cdvfile://localhost/persistent/path/to/Download/"; 是错误的,但我真的不知道实际路径是什么。请帮帮我
【问题讨论】:
-
我在这里找到了从服务器下载的文件 ///data/user/0/com.app.nEnhance/files/files/path/to/android.apk 当我尝试点击安装时我得到了同样的错误是解析错误..
标签: android cordova auto-update