Created
August 16, 2017 11:43
-
-
Save meghnasmoorthy/d645dd996d9d30d945d4632e9631952e to your computer and use it in GitHub Desktop.
Trigger app update programatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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