簡體   English   中英

android cordova app以編程方式觸發更新

[英]android cordova app trigger update programmatically

我使用此代碼從我的localhost下載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/"; 是錯的,但我真的不知道實際的路徑是什么。 請幫我

好吧我已經解決了我的問題。 我放在這里,因為有人遇到同樣的問題。 它的真實,我放的路徑實際上是錯誤的,因為我得到了apk我下載表單服務器,但無法安裝它因為它沒有權限,因為它puth在root用戶所以我改變路徑到

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

然后在成功下載文件之后,web intent會自動提示用戶安裝與否。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM