Ionic Auto Upgrade App (Android version)

Source: Internet
Author: User

Ionic Framework Introduction
Ionic is a angularjs-based, user-interface framework that uses HTML5 to build hybrid mobile apps, claiming to be "a combination of local and HTML5." The framework provides a number of basic mobile user interface examples, such as simple entries like List (lists), tab bar (tab bars), and trigger switch (toggle switches). It also provides examples of more complex visual layouts, such as the slide-out menu showing content below. Ionic Auto-upgrade app
First, the preparatory work
1.Cordova Plugins:
Cordova Plugin Add https://github.com/whiteoctober/cordova-plugin-app-version.git//Get App version Cordova plugin add ORG.A Pache.cordova.file//File system Cordova Plugin add org.apache.cordova.file-transfer//File transfer System Cordova plugin add https:/ /github.com/pwlin/cordova-plugin-file-opener2//File Open System
2.AngularJS Cordova Plug-in
Ngcordova
Second, the relevant code, app.js copy Code
. Run ([' $ionicPlatform ', ' $rootScope ', ' $ionicActionSheet ', ' $timeout ', ' $cordovaAppVersion ', ' $ionicPopup ', ' $ Ionicloading ', ' $cordovaFileTransfer ', ' $cordovaFile ', ' $cordovaFileOpener 2 ', function ($ionicPlatform, $rootScope, $ Ionicactionsheet, $timeout,  $cordovaAppVersion, $ionicPopup, $ionicLoading, $cordovaFileTransfer, $cordovaFile , $cordovaFileOpener 2) {        $ionicPlatform. Ready (function ($rootScope) {            /Hide the accessory bar by default (remove this to S How the accessory bar above the keyboard            /for Form I nputs)             if (Window.cordova && Window.cordova.plugins.Keyboard) {                 Cordova.plugins.Keyboard.hideKeyboardAccessoryBar (TRUE);            }              if (window. StatusBar) {               // Org.apache.cordova.statusbar Required                  Statusbar.styledefault ();            }
Detect update checkupdate ();
Document.addeventlistener ("Menubutton", Onhardwaremenukeydown, false); });
       //Menu keys         function Onhardwaremenukeydown () {            $ Ionicactionsheet.show ({                 TitleText: ' Check for updates ',                  buttons: [                     {text: ' About '}                 ],                 Destructivetext: ' Check for updates ',                  Canceltext: ' Cancel ',                  Cancel:function () {                   / /Add Cancel Code:                },                  destructivebuttonclicked:function () {                     //Check for updates                      checkupdate ();                },                  buttonclicked:function (Index) {
}             });             $timeout (function () {hidesheet ();         }, 2000); };
       //Check for updates         function checkupdate ( {            var serverappversion = "1.0.0";//Get the latest version from the Server & nbsp;          //Get version              $cordovaAppVersion. Getappversion (). Then (function (version) {                //If the app version on the local and server side does not conform to                  if (version! = serverappversion) {                     Showupdateconfirm ();                }             });        }
       //Show update dialog box         function Showupdateconfirm () {            var confirmpopup = $ Ionicpopup.confirm ({                Title: ' Version upgrade ',                 Template: ' 1.xxxx;</br>2.xxxxxx;</br>3.xxxxxx;</br>4.xxxxxx ',//get updated content from the server                  canceltext: ' Cancel ',                  oktext: ' Upgrade '             });             Confirmpopup.then (function (res) {               &nbsp if (res) {                     $ionicLoading. Show ({                         Template: "Downloaded: 0%"                     });                      var url = "http://192.168.1.50/1.apk"; The path to the update app can be obtained from the server                      var TargetPath = "file:///storage/sdcard0/Download/1.apk"; The path to the app download, which can be configured using the Cordova file plugin                      var trusthosts = True                     var options = {};                      $cordovaFileTransfer. Download (URL, TargetPath, Options, trusthosts). Then (function (result) {                         //Open downloaded Apps                          $cordovaFileOpener 2.open (TargetPath, ' application/ Vnd.android.package-archive '                         ). Then (function () {                                 //Success                             }, function (err) {                                 //Error                              });                          $ionicLoading. Hide ();                     }, function (err) {                         AlerT (' download failed ');                     }, function (progress) {                        //progress, here Use text to display download percent                          $ Timeout (function () {                             var downloadprogress = (progress.loaded/ progress.total) * 100;                              $ionicLoading. Show ({                                 Template: "Already downloaded:" + math.floor ( downloadprogress) + "%"                             });                              if (downloadprogress > ©) {                                  $ionicLoading. Hide ();                             }                         })                     });                } else {                    //Cancel Updates                }             });        }    }])

The above is a simple implementation, some of the data are written here dead, you can get some data from the server, such as the latest version number, the most recent download path, here is a thought.

Project Address: HTTPS://GITHUB.COM/ZXJ963577494/IONIC-AUTOUPDATEAPP

Simply execute Ionic build Android

From: http://www.cnblogs.com/zxj159/p/4421578.html

Ionic Auto Upgrade App (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.