The use of Android development xutils-httputils

Source: Internet
Author: User

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

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.