Android network access (xutils3)

Xutils3 is an important library for Android network access. Basically, the contents involved in network requests are integrated. The author will realize the simple use of xutils3, including simple get and post requests, file upload, file download and image display.

Its main characteristics are as follows:

① Provide asynchronous network requests

② Support upload of super large files (over 2G)

③ With strong HTTP and its download cache support, file breakpoint continuation is supported

④ Comprehensive HTTP request protocol support (get, post, etc.)

⑤ Image binding supports GIF (affected by system compatibility, some GIF files can only be displayed statically), round, round and square display of images, image clipping and automatic rotation

Initialization work:

Add dependency

New initialization class

Create a new class: xutilisinit. Put the new class under the same level directory of mainactivity (under the same package)

Necessary permission acquisition and class declaration

In androidmanifest.xml, the first permission is network access permission and the second is file read-write permission. File read-write permission needs to be obtained manually on some mobile phones, otherwise it will affect the file upload and download functions.

Simple get and post request implementation:

You don't need to start another thread, just write it directly in the main thread, and the framework realizes thread access.

Post file upload:

Upload files in the form of post submission form, where params. Setmultipart (true); Yes means to upload data in binary mode. This sentence must be added when file upload is required.

File download implementation:

Asynchronous tasks are used for file downloading. It also implements the function of breakpoint continuation. Viewing the download folder, you can see that a cache file will be automatically generated during downloading to store the downloaded content. The basic judgment should be that the downloaded file will be compared with the cache file next time to realize the breakpoint continuation function.

Picture display:

Imageoptions is a powerful tool class for loading and displaying network pictures. It can realize picture caching, right angle, rounded corner, circular display and picture clipping. In addition, it also supports GIF dynamic display.

Display effect

Picture display encapsulation class

Use in required display

reference resources:

https://github.com/wyouflf/xUtils3

https://blog.csdn.net/u014620028/article/details/51063377

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>