Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Xutils3 for breakpoint download of Android

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how Android uses Xutils3 for breakpoint downloads. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Using tools: Android studio 3.0

How to use it:

One: add dependency in build.gradle (Module:app)

Implementaion 'org.xutils:xutils:3.5.1'

Second: create a separate MyApp class to initialize xutils. The class name can be customized.

Public class MyApp extends Application {@ Override public void onCreate () {super.onCreate (); x.Ext.init (this);}}

Three: add permissions to AndroidManifest and register MyApp

/ / add permissions / / register MyApp

Add android:name= ".MyApp'to the node

Four: use the download method

Public void download (View view) {String path=et.getText (). ToString (). Trim (); RequestParams params=new RequestParams (path); params.setSaveFilePath (Environment.getExternalStorageDirectory () + "/ myapp/"); params.setAutoRename (true) X.http () .post (params,new Callback.ProgressCallback () {@ Override public void onWaiting () {} @ Override public void onStarted () {} @ Override public void onLoading (long total, long current, boolean isDownloading) {pd.setMax ((int) total); pd.setProgress ((int) current) } @ Override public void onSuccess (File result) {Log.i ("TEST", "download completed");} @ Override public void onError (Throwable ex, boolean isOnCallback) {} @ Override public void onCancelled (CancelledException cex) {} @ Override public void onFinished () {}});}

Knowledge point expansion:

Introduction to xUtils3

XUtils includes orm, http (s), image, and view annotations, but it is still lightweight (246k) and has powerful features that make it easy to extend:

The cornerstone of stability: AbsTask and unified callback interface Callback. Any exception, even if there is an exception in your callback method implementation, will enter onError. In any case, onFinished will let you know that the task is over. Based on the efficient and stable orm tools, the http module can more easily support cookie (supporting domain, path, expiry, etc.) and cache (supporting Cache-Control, Last-Modified, ETag, etc.). With powerful support for http and its download cache, the implementation of the image module is quite simple, and supports recycling images held by view but removed by Mem Cache, reducing flicker during page fallback. The view annotation module flexibly supports all kinds of View injection and event binding, including listener with more methods.

Thank you for reading! This is the end of the article on "how to download breakpoints with Android using Xutils3". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report