【问题标题】:android cordova app trigger update programmaticallyandroid cordova 应用程序触发器以编程方式更新
【发布时间】: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


【解决方案1】:

好的,我已经解决了我的问题。我放在这里以防有人遇到同样的问题。确实,我输入的路径是错误的,因为我得到了我下载表单服务器的apk,但无法安装它,因为它没有权限,因为它以root用户身份输入,所以我将路径更改为

var fileURL = cordova.file.externalDataDirectory+'android.apk'

然后在成功下载文件后,网络意图会自动提示用户安装与否。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多