1024programmer Blog HB packaged apk for upgrade_apkhb

HB packaged apk for upgrade_apkhb

 document.addEventListener('plusready', function() {
        var first = null;
         document.addEventListener("netchange",onNetChange,false);
         function onNetChange(){
           //Get the current network type
           var nt = plus.networkinfo.getCurrentType();
           switch(nt){
             case plus.networkinfo.CONNECTION_ETHERNET:
             case plus.networkinfo.CONNECTION_WIFI:
               mui.toast("The network is connected");
               break;
             default:
               mui.toast("The network has been disconnected");
               break;
           }
         }

        var webview = plus.webview.currentWebview();
         plus.key.addEventListener('backbutton', function() {
           document.addEventListener("netchange",onNetChange,false);
           webview.canBack(function(e) {
             if (e.canBack) {
               webview.back();
             } else {
               if (!first) {
                 first = new Date().getTime();
                 mui.toast('Click again to exit the application');
                 setTimeout(function() {
                   first = null;
                 }, 1000);
               } else {
                 if (new Date().getTime() - first < 1000) {
                   plus.runtime.quit();
                 }
               }
             }
           })
         });




       //plus object upgrade
       if(plus) {
         var btn = ["Confirm upgrade", "Cancel"];
         plus.runtime.getProperty(plus.runtime.appid, function(inf) {
           ver = inf.version;
           console.log(ver)
           ajaxurl = "http://xxxxxxxx";//Backend address
           $.ajax({
             url: ajaxurl+'/common/version',
             success: function(data) {
               console.log(data)
               console.log(data.result.version)
               if (data.result.version != ver) {
                 var _msg = "Current version: V" + ver+", latest version number: V" + data.result.version;

                 // var _msg = "Current version: V" + data.result.version;
                 mui.confirm(_msg, 'Upgrade confirmation', btn, function(e) {
                   if (e.index == 0) { //Perform upgrade operation
                      plus.nativeUI.showWaiting( "The environment is being prepared, please wait patiently!" );
                      var dtask = plus.downloader.createDownload(data.result.downloadURL, {

                     }, function(d, status) {

                       if (status == 200) {
                         var path = d.filename; //Download apk
                         plus.runtime.install(path); // Automatically install apk files
                         plus.nativeUI.closeWaiting(); //After downloading, showwait disappears
 

                       } else {
                         plus.nativeUI.alert('Version update failed:' + status);
                       }
                     });
                     dtask.start();
                   }
                 });
               } else {
                 mui.toast('The current version number is the latest');

                 return;
               }
             },
             error: function(xhr, type, errerThrown) {
               mui.toast('Network abnormality, please try again later');

             }
           });
         });
       }

       });

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/hb-packaged-apk-for-upgrade_apkhb/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索