0
我正在嘗試實現自動更新功能,以便在常規市場之外分發應用。 我使用cordova插件的組合來下載和執行我的應用的更新版本。meteor cordova應用內apk安裝更新默默無效
我可以看到,我將apk下載到外部存儲,啓動它,允許安裝但沒有任何反應(它回到我的原始應用程序)。
我有一種感覺,這是一個權限問題,但我在日誌中看不到任何東西。 如果我打開從文件系統下載的apk,我可以安裝它沒有任何問題。 這只是當我從cordova應用程序啓動apk時,安裝不起作用。
這裏是我用來進行更新的代碼:
/**
* Begin the download and install of the update for android.
*/
update() {
let _this = this;
let update = this._updateResult.get();
// Check permissions first
let permissions = cordova.plugins.permissions;
let list = [permissions.WRITE_EXTERNAL_STORAGE];
let errorPermissions =() => {
sAlert.error("Cannot update permissions");
};
let successPermissions =() => {
let fileTransfer = new FileTransfer();
// let targetLocation = cordova.file.externalDataDirectory + "app.apk"; // better use externalCacheDirectory
let targetLocation = "file:///storage/emulated/0/Download/"+"app-1.4.1.apk";
console.debug("Begin update in appManager ", update);
console.info("Download file", update.apk);
console.info("Download to ", targetLocation);
let onSuccess = (entry) => {
let fileURL = entry.toURL();
console.debug("download complete!", fileURL);
cordova.plugins.fileOpener2.open(
fileURL,
'application/vnd.android.package-archive',
{
error: function (e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
_this._updating.set(false);
},
success: function() {
console.log('file opened successfully');
_this._updating.set(false);
}
}
);
}
let onError = (error) => {
_this._updating.set(false);
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("download error code" + error.code);
}
let options = {
chunkedMode: true,
mimeType: "application/vnd.android.package-archive"
};
fileTransfer.download(
encodeURI(update.apk),
targetLocation,
onSuccess,
onError,
options,
true // trustAllHosts
);
fileTransfer.onprogress = (progressEvent) => {
if (progressEvent.lengthComputable) {
let percent = Math.floor((progressEvent.loaded/progressEvent.total) * 100);
_this._updating.set(percent);
} else {
_this._updating.set(true);
}
};
}
permissions.hasPermission(list,
function (status) {
console.debug("permissions status is", status);
if (status.hasPermission) {
successPermissions();
} else {
permissions.requestPermissions(
list,
function (status) {
if (!status.hasPermission) {
errorPermissions();
}
successPermissions();
},
errorPermissions
);
}
}, errorPermissions);
}
我也試圖添加像INSTALL_PACKAGES,DELETE_PACKAGES,許可權等權限...
我想的唯一的重要組成部分代碼應該是
cordova.plugins.fileOpener2.open(
fileURL,
'application/vnd.android.package-archive',
{
error: function (e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
_this._updating.set(false);
},
success: function() {
console.log('file opened successfully');
_this._updating.set(false);
}
}
);
我的日誌顯示「文件打開成功」,任何幫助非常感謝:)