【发布时间】:2019-05-10 07:07:08
【问题描述】:
我使用 Cordova 开发了一个适用于 android 的应用程序(现在在 playstore 上),现在实现了自动更新。以下是我正在使用的插件列表
- cordova-plugin-app-version
- cordova 插件文件
- cordova-plugin-file-transfer
- cordova-plugin-android-permissions
- cordova-plugin-file-opener2(我试过 webIntent 插件,但对我不起作用)。
当我安装下载的 APK 时,它会关闭而不是显示“打开屏幕”。
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
var permissions = cordova.plugins.permissions;
permissions.checkPermission(permissions.WRITE_EXTERNAL_STORAGE, function (status) {
console.log(status);
if (!status.hasPermission) {
var errorCallback = function () {
console.log("Error: app requires storage permission");
};
permissions.requestPermission(permissions.WRITE_EXTERNAL_STORAGE,
function (status) {
if (!status.hasPermission)
errorCallback();
else {
downloadFile(fileSystem);
}
},
errorCallback);
}
else {
downloadFile(fileSystem);
}
}, null);
var downloadFile = function (fileSystem) {
var localPath = 'file:///storage/emulated/0/download/myApp.apk',
fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI("URL"), localPath, function (entry){
cordova.plugins.fileOpener2.open(
entry.nativeURL,
'application/vnd.android.package-archive',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
}, function (error) {
console.log("Error downloading the latest updates! - error: " + JSON.stringify(error));
});
};
},function ( evt ) {
console.log( "Error preparing to download the latest updates! - Err - " + evt.target.error.code );
message = "Error preparing to download the latest updates, Try again later";
});
【问题讨论】:
-
不,不是,我已经看到了,但这不是我所面临的。
-
它是否以不同的方式崩溃?
-
是的,在安装应用程序被杀死后,我没有收到任何消息。如果我再次打开它,它在更新版本上工作得很好。
标签: javascript android cordova