Use utuils frame to upgrade online, display ProgressDialog, automatically eject the installation screen after downloading.
1 Private voidupdatedownload () {2 //detect if a memory device is available3 if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {4 //Set Storage Path5 FinalString Targer = environment.getexternalstoragedirectory () + "/update.apk";6LOG.E ("Test", "Storage path:" +Targer);7Httputils Utils =Newhttputils ();8LOG.E ("Test", "Create Httputils");9 TenUtils.download (Mdownloadurl, Targer,NewRequestcallback<file>() { One //Set ProgressDialog AProgressDialog ProgressDialog =NewProgressDialog (splashactivity. This); - //Update download Progress - @Override the Public voidOnloading (LongTotalLongCurrentBooleanisuploading) { - Super. onloading (Total, Current, isuploading); -LOGUTILS.E ("Progress:" +Current ); -Progressdialog.settitle ("Downloading:"); + - //set current download progress as a percentage + intBar = (int) (Current*100/Total ); AProgressdialog.setmessage ("Current Download:" + Bar + "%"); at //show the progress. - progressdialog.show (); - } - - //Success - @Override in Public voidOnsuccess (responseinfo<file>responseinfo) { -LOG.E ("Test", "Download succeeded"); to //Open the installation package +Intent Intent =NewIntent (intent.action_view); - intent.addcategory (intent.category_default); the Intent.setdataandtype (Uri.fromfile (responseinfo.result), *"Application/vnd.android.package-archive"); $ //startactivity (intent);Panax Notoginseng //If the user cancels the installation, the result is returned, and the callback method Onactivityresult -Startactivityforresult (Intent, 0); the } + A //failed the @Override + Public voidonfailure (HttpException E, String s) { -Toast.maketext (splashactivity. This, "Download Failed", toast.length_short); $ enterhome (); $ } - - }); the}Else { - //No memory cardWuyiToast.maketext (splashactivity. This, "No storage device detected", toast.length_short); the enterhome (); - } Wu - } About $ //when the user cancels the installation of the software - @Override - protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { - Super. Onactivityresult (Requestcode, ResultCode, data); A enterhome (); +}
Software update related, using Utuils framework online upgrade, display ProgressDialog, download finished automatically eject the installation interface.