Use the network section of the Xutils framework Httputils, features: Download, breakpoint continuation, ProgressBar display progress, text display progress%
1 ImportJava.io.File;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 Importandroid.os.Environment;6 ImportAndroid.view.View;7 ImportAndroid.widget.ProgressBar;8 ImportAndroid.widget.TextView;9 ImportAndroid.widget.Toast;Ten One Importcom.lidroid.xutils.HttpUtils; A Importcom.lidroid.xutils.exception.HttpException; - ImportCom.lidroid.xutils.http.ResponseInfo; - ImportCom.lidroid.xutils.http.callback.RequestCallBack; the - Public classMainactivityextendsActivity { - PrivateProgressBar PB; - PrivateTextView Tv_error; + PrivateTextView tv_progress; - + @Override A protected voidonCreate (Bundle savedinstancestate) { at Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -PB =(ProgressBar) Findviewbyid (R.ID.PB); -Tv_progress =(TextView) Findviewbyid (r.id.tv_progress); -Tv_error =(TextView) Findviewbyid (r.id.tv_error); - in } - to Public voidClick (View v) { +String fileName = "Bcompare.exe"; -String Path = "http://192.168.1.40:8080/" +FileName; theHttputils http =Newhttputils (); *Http.download (Path, environment.getexternalstoragedirectory () + "/" $+ FileName,true,true,NewRequestcallback<file>() {Panax Notoginseng - @Override the Public voidOnsuccess (responseinfo<file>arg0) { +Toast.maketext (mainactivity. This, Arg0.result.getPath (), 0) A . Show (); the } + - @Override $ Public voidonfailure (HttpException arg0, String arg1) { $ Tv_error.settext (arg1); - } - the @Override - Public voidOnloading (LongTotalLongCurrentBooleanisuploading) {Wuyi Super. onloading (Total, Current, isuploading); thePb.setmax ((int) total); -Pb.setprogress ((int) (current); WuTv_progress.settext (Current * 100/total + "%"); - } About $ }); - } -}
The use of Android development xutils-httputils