The principle of app upgrade is very simple, get the latest version of the service side of the release information, and its own version of the information, if its own version is low, you can prompt users to download the new version.
For Android apps, version information is primarily stored in the Androidmanifest.xml file:
<manifest android:hardwareaccelerated= "true" android:versioncode= "101" android:versionname= "1.0.1" Android: Windowsoftinputmode= "Adjustpan" package= "Net.jiusem.tjlib" xmlns:android= "http://schemas.android.com/apk/res/android" >
Android:versioncode represents the version number, which is an integer, Android:versionname represents the version name and a string separated by a dot.
The key to detecting whether an app needs to be updated is to get to the Versioncode and compare it to the Versioncode on the server, if it's smaller than the server, it means the app has a new version and needs to be updated.
There is a plugin to get to the app's Versioncode, the installation method is as follows:
Cordova Plugin Add Https://github.com/whiteoctober/cordova-plugin-app-version.git
Get Versioncode:
Cordova.getAppVersion.getVersionNumber (function (version) {alert (version);});
Complete client and server-side code examples:
Check Update method function Checkupdate () {//check update address var url = ' http://app.test.com/TjLib/check_update.php '; cordova.getappversio N.getversioncode (function (versioncode) {$.post (url,{},function (data) {var obj = json.parse (data); if (Versioncode < Obj.versioncode) {//When an update is detected, the user is prompted whether to upgrade var R = Confirm (obj.msg), if (r) {///Call Browser opens download link, need to install Inappbrowser plug-in window.open (obj. APK, ' _system ', ' Location=yes ');}}); The app is invoked once settimeout (function () {checkupdate ();},5000); server-side code reference (PHP) <?php//Check for Update call $data = Array (' Versioncode ' = >102,//version number ' versionname ' = ' 1.0.1 ',//version name ' msg ' = ' = ' There is a new version available for update. \ n 1. UI beautification \ n 2. Performance optimization ",//Update prompt ' apk ' =/ app.test.com/tjlib/tjlib1.0.1.apk '//app); Echo Json_encode ($data);? >
CORDOVA/PHONEGAP Application Implementation detection upgrade (Android version)