Multi‑thread breakpoint download implementation in Android 2. Use the open-source framework XUtils and Android xutils

Source: Internet
Author: User

Multi‑thread breakpoint download implementation in Android 2. Use the open-source framework XUtils and Android xutils

The use of open-source frameworks can greatly reduce the difficulty of development, reduce the development cycle, and have fewer bugs, making the software more stable to run.

Introduction to xUtils

XUtils contains many practical android tools.
XUtils supports large file uploads, more comprehensive http request protocol support (10 predicates), more flexible ORM, more event annotations supported and not affected by obfuscation...
Least compatible with android 2.2 (api level 8)

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

The following is a demo:

Public class MainActivity extends Activity {private EditText et_path; private TextView 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, "Enter the download path", 0 ). show (); return;} else {HttpUtils http = new HttpUtils (); HttpHandler handler = http. download (path, "/sdcard/xxx.zip", true, // if the target file exists, download the unfinished part. When the server does not support RANGE, it will be downloaded again. True, // if the file name is obtained from the returned information of the request, it is automatically renamed after the download is complete. New RequestCallBack <File> () {@ Override public void onStart () {TV _info.setText ("conn... ") ;}@ Override public void onLoading (long total, long current, boolean isUploading) {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 );}});}}}

The use of open-source frameworks is far more beneficial!

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.