Multi-threaded breakpoint download implementation under Android 2 leverage open source framework Xutils

Source: Internet
Author: User

The use of open source framework can greatly reduce the difficulty of development, reduce the development cycle, and fewer bugs, software run more stable.

Xutils Introduction

Xutils contains a lot of useful Android tools.
Xutils supports large file uploads, more comprehensive HTTP request protocol support (10 predicates), more flexible ORM, more event annotations support, and is not affected by confusion ...
XUITLS Minimum compatible Android 2.2 (API Level 8)

: Https://github.com/wyouflf/xUtils

Here is a demo:

 Public  class mainactivity extends Activity {    PrivateEditText Et_path;PrivateTextView Tv_info;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        Et_path = (EditText) Findviewbyid (R.id.et_path);    Tv_info = (TextView) Findviewbyid (r.id.tv_info); } Public void Download(View view) {String path = Et_path.gettext (). toString (). Trim ();if(Textutils.isempty (path)) {Toast.maketext ( This,"Please enter the path of the download",0). Show ();return; }Else{Httputils http =NewHttputils (); HttpHandler handler = http.download (Path,"/sdcard/xxx.zip",true,//If the destination file exists, then the unfinished portion continues to download. The server does not support range when it is newly downloaded.                     true,//If the file name is obtained from the request return information, it is automatically renamed after the download is complete.                     NewRequestcallback<file> () {@Override                         Public void OnStart() {Tv_info.settext ("Conn ..."); }@Override                         Public void onloading(LongTotalLongCurrentBooleanisuploading) {Tv_info.settext (current +"/"+ total); }@Override                         Public void onsuccess(responseinfo<file> responseinfo) {Tv_info.settext ("Downloaded:"+ ResponseInfo.result.getPath ()); }@Override                         Public void onfailure(httpexception error, String msg)                        {Tv_info.settext (msg);        }                }); }    }}

With a ready-made open source framework, the benefits are great!

Multi-threaded breakpoint download implementation under Android 2 leverage open source framework Xutils

Related Article

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.