CORDOVA/PHONEGAP Application Implementation Detection upgrade (Android version)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.