Skip to content

Instantly share code, notes, and snippets.

@meghnasmoorthy
Created August 16, 2017 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meghnasmoorthy/d645dd996d9d30d945d4632e9631952e to your computer and use it in GitHub Desktop.
Save meghnasmoorthy/d645dd996d9d30d945d4632e9631952e to your computer and use it in GitHub Desktop.
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