I've developed an app for android using Cordova(it's now on playstore) and now implementing autoupdate. Below are the lists of plugin i am using
- cordova-plugin-app-version
- cordova-plugin-file
- cordova-plugin-file-transfer
- cordova-plugin-android-permissions
- cordova-plugin-file-opener2(I've tried webIntent plugin but that is not working for me).
When i install the downloaded APK, it's getting closed instead of showing me "open screen".
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";
});