Я разработал приложение для Android с использованием Cordova (теперь оно в PlayStore) и теперь внедряю автообновление. Ниже приведены списки плагинов, которые я использую
- Cordova-плагин-приложение-версия
- Cordova-плагин-файл
- Cordova-плагин-передачи файлов
- Cordova-плагин-андроид-разрешение
- 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";
});