Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Trigger app update programatically
function doWeHaveLatestVersion(){
return true;//compare app version with version of apk in server
}
if(!doWeHaveLatestVersion()){
fileUri="file:///storage/emulated/0/";
window.resolveLocalFileSystemURL(
fileUri,
onFileResolved,
onFileResolveError);
function onFileResolved(fe){
fe.getFile('appname.apk', {
create: true,
exclusive: false
}, function(fileEntry) {
console.log("apk donwload started")
var localPath = fileEntry.toURL(),
fileTransfer = new FileTransfer();
var apkURL = encodeURI("location of the latest apk");
fileTransfer.download(apkURL, localPath, function(entry) {
console.log("apk download complete");
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: entry.toURL(),
type: 'application/vnd.android.package-archive'
},
function(data){console.log("webintent succeeded, data:"+data)},
function(e){
console.log('Error launching app update'+e);
}
);
console.log("apk installation triggered");
}, function (error) {
console.log("Error downloading APK: " + error.message);
});
}, function(evt){
console.log("error getting root filesytem: " + evt);
});
console.log("resovled the root folder,URL"+fe.toURL())
}
function onFileResolveError(er){
console.log("Error while resolving the root folder:"+er.message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.