Android download function example based on the built-in downloadmanager

This article describes the download function of Android based on its own downloadmanager. Share with you for your reference, as follows:

Downloadmanager.enqueue adds a download request to the download management class and returns a download ID.

Large files can only be downloaded under WiFi

You need to register a downloaded broadcast and customize it

Intent.getlongextra here (downloadmanager.extra_download_id, - 1); Downloadmanager.extra_ DOWNLOAD_ ID is a parameter in the downloadmanager class. Use the following method to register the broadcast

The intentfilter used is the downloaded filter

Then the broadcast will be notified, and the returned intent contains downloadmanager.extra_ DOWNLOAD_ Parameter for ID.

For other uses of downloadmanager, see the API documentation

Here is the usage of downloadmanager. Query.

Obviously, query is an inner class. There are two methods: query.setfilterbyid and query.setfilterbystatus,

Query.setfilterbyid is to put the ID returned by downloadmanager.enqueue as the query condition;

Conditions for splicing query.

The query used here queries the downloads database, but only the data downloaded by the application can be queried

Therefore, it is not feasible to query all download records of the system through downloadmanager. Query.

But what if there is demand?

Remember that there are user contacts in apidemo. Use URI to query contact contacts. When you enter root explore and observe the DB database content in com.android.providers.downloads package, you find that there are contacts in the downloaded records content://media/external/file/452122

This content, so you can get the downloaded file in this way

Fields returned under test

Extract fields according to your needs.

More readers interested in Android related content can view the topics on this site: summary of Android basic component usage, introduction and advanced tutorial of Android development, summary of Android layout skills, summary of Android view skills, summary of activity operation skills of Android programming, summary of Android resource operation skills, and Android control usage summary

I hope this article will help you in Android programming.

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
分享
二维码
< <上一篇
下一篇>>