Ionic upgrade APP (Android) and ionicandroid
Ionic framework
Ionic is a user interface framework based on Angularjs that can use HTML5 to build hybrid mobile applications. It is called "local and HTML5 combination ". This framework provides many basic examples of mobile user interfaces, such as simple entries such as lists, tab bars, and toggle switches. It also provides more complex visual layout examples, such as the slide-out menu of the content displayed below.
Ionic automatically upgrades the APP
I. Preparations
1. Cordova Plugin:
Cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.git // get APP version
Cordova plugin add org. apache. 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 opening system
2. AngularJS Cordova plugin
NgCordova
Ii. Related code, app. js
. Run (['$ ionicPlatform', '$ rootScope', '$ ionicActionSheet', '$ timeout',' $ cordovaappversion', '$ ionicPopup', '$ ionicLoading ', '$ cordovaFileTransfer', '$ cordovaFile', '$ callback', function ($ ionicPlatform, $ rootScope, $ ionicActionSheet, $ timeout, $ cordovaAppVersion, $ ionicPopup, $ ionicLoading, $ cordovaFileTransfer, $ cordovaFile, $ cordovaFileOpener2) {$ ionicPlatform. ready (function ($ rootScope) {// Hide the accessory bar by default (remove this to show the accessory bar abve the keyboard // for form inputs) if (window. cordova & window. cordova. plugins. keyboard) {cordova. plugins. keyboard. hideKeyboardAccessoryBar (true);} if (window. statusBar) {// org. apache. cordova. statusbar required StatusBar. styleDefault ();} // check for update checkUpdate (); document. addEventListener ("menubutton", onHardwareMe NuKeyDown, false) ;}); // menu key function onHardwareMenuKeyDown () {$ ionicActionSheet. show ({titleText: 'check Update', buttons: [{text: ''}], destructiveText: 'check Update', cancelText: 'cancel', cancel: function () {// add cancel code ..}, destructiveButtonClicked: function () {// check for update checkUpdate () ;}, buttonClicked: function (index) {}}); $ timeout (function () {hideSheet ();}, 2000) ;}; // check the updated function ch EckUpdate () {var serverAppVersion = "1.0.0"; // obtain the latest version from the server. // obtain the version $ cordovaAppVersion. getAppVersion (). then (function (version) {// if the local and server APP versions do not match if (version! = ServerAppVersion) {showUpdateConfirm () ;}}) ;}// display whether to update the dialog box function showUpdateConfirm () {var confirmPopup = $ ionicPopup. confirm ({title: 'version upgrade', template: '1. xxxx; </br> 2. xxxxxx; </br> 3. xxxxxx; </br> 4. xxxx', // obtain the updated content from the server. cancelText: 'cancel', okText: 'upgrade'}); confirmPopup. then (function (res) {if (res) {$ ionicLoading. show ({template: "downloaded: 0%"}); var url = "http: // 192.168.1.50/1.apk "; // you can obtain the path of the updated APP from the server. var targetPath = "file: // storage/sdcard0/Download/1.apk"; // The path where the APP is downloaded and stored, you can use the cordova file plug-in to configure var trustHosts = true var options ={}; $ cordovaFileTransfer. download (url, targetPath, options, trustHosts ). then (function (result) {// open the downloaded APP $ cordovaFileOpener2.open (targetPath, 'application/vnd. android. package-archive '). then (function () {// success}, function (err) {// error}); $ ionicLoading. hide () ;}, function (err) {alert ('Download failed') ;}, function (progress) {// progress, the text shows the download percentage $ timeout (function () {var downloadProgress = (progress. loaded/progress. total) * 100; $ ionicLoading. show ({template: "downloaded:" + Math. floor (downloadProgress) + "%"}); if (downloadProgress> 99) {$ ionicLoading. hide () ;}}) };}else {// cancel the update}) ;}}])
The above is a simple implementation method. Some data is written here, and you can get some data from the server, such as the latest version number and the latest download path. Here is an idea.
Project address: https://github.com/zxj963577494/ionic-AutoUpdateApp
You only need to execute ionic build android.