Ionic Android Upgrade Check

Source: Internet
Author: User

Https://www.cnblogs.com/zxj159/p/4421578.html

Keng:

Drop to cordova.file.DataDirectory download exception? Had to Cordova.file.externalDataDirectory

Code
        //Check for updates        $scope.Appupdatecheck = function(init){            varInit=Init|| 0;            //Appupdateservice.showupdateconfirm ({});            //return;            Versionservice.Get({ Platform: Ionic.Platform.Platform()}, function(RESP){                //Alert (Json.stringify (RESP))                if(resp.Code == ' a '){                    //Alert (resp.data.version)                    //Alert ($cordovaAppVersion. GetVersionNumber ())                    //Alert ($cordovaAppVersion. Getversioncode ())                    Cordova.getappversion.GetVersionNumber(function(version){                        //alert (version)                        if(Version== resp.Data.version){                            if(!Init{                                Messageservice.Show(' Currently the latest version ');                            }                            return;                        }                        $scope.hasnewversion = 1;                        $scope.Device_items[1].name = $sce.trustashtml(' upgrade check <font style= ' color: #FD1F38 ' >-new!</font> ');                        if(!Init{                            Appupdateservice.showupdateconfirm(resp.Data);                        }                    });                } Else {                    Messageservice.Show(resp.msg);                }            });        }
 ;(function(angular){    Angular.Module(' Mobile ')        .Factory(' Appupdateservice ',[' $cordovaFileTransfer ', ' $cordovaFileOpener 2 ', ' $ionicPopup ', ' $ionicLoading ', ' $timeout ', ' Messageservice ',            function($cordovaFileTransfer,$cordovaFileOpener 2,$ionicPopup,$ionicLoading,$timeout,Messageservice){                //Show whether to update the dialog box                function showupdateconfirm(Versioninfo){                    varVersioninfo=Versioninfo;                    varDownloadURL= Versioninfo.URL,Updatelog= Versioninfo.Upgradeinfo,TargetPath= ' file:///storage/sdcard0/Download/XiaoShuTong.apk ' //app Download the stored path, you can use the Cordova file plugin to configure the relevant                    //TODO test Data                    //DownloadURL = ' http://imtt.dd.qq.com/16891/006473EB7690D8B89DEBD9613BF9E40E.apk?fsname=com.tencent.mm_ 6.6.0_1200.apk '                    //Updatelog = ' 1. Update module upgrade <br>2. Fix 1 bug<br> 'TargetPath= Cordova.file.externaldatadirectory + ' xiaoshutong.apk '                    varConfirmpopup= $ionicPopup.Confirm({                        title: ' version upgrade ',                        Template:Updatelog, //Get updated content from the server                        Canceltext: ' Cancel ',                        Oktext: ' Upgrade '                    });                    Confirmpopup. Then(function(RES){                        if(RES){                            //if (ionic. Platform.isios ()) {                            ///Prompt to enter the APP store                            //Messageservice.show (' Please go to the App Store to upgrade. ');                            // }                            if(Ionic.Platform.isandroid()&&DownloadURL!= "'){                                $ionicLoading.Show({                                    Template: "Downloaded: 0%"                                });                                $cordovaFileTransfer.Download(DownloadURL,TargetPath, NULL, true). Then(function(Result){                                    //Open the downloaded app                                    $cordovaFileOpener 2.Open(TargetPath, ' application/vnd.android.package-archive '). Then(function(){                                        //Success                                    }, function(ERR){                                        //Error                                        //alert (' Install file failed to open, please try to install manually. ');                                        Messageservice.Show(' installation file failed to open, please try to install manually. ');                                    });                                    $ionicLoading.Hide();                                }, function(Error){                                    $ionicLoading.Hide();                                    //Alert (json.stringify (Error));                                    //Messageservice.show (json.stringify (Error));                                    Messageservice.Show(' Please set the application file operation permissions and try again. ');                                }, function(progress){                                    varDownloadProgress= Math. Floor((Progress.Loaded/Progress. Total)*  -);                                    if(downloadprogress> 0){                                        $ionicLoading.Show({                                            Template: ' already downloaded: ' +DownloadProgress+ '% '                                        });                                    }                                    if(downloadprogress>  About){                                        $ionicLoading.Hide();                                    }                                });                            }                        } Else {                            //Cancel update                            $ionicLoading.Hide();                        }                    });                }                //Return                return {                    showupdateconfirm:Showupdateconfirm}            }]); }) (angular);

Ionic Android Upgrade Check

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.