Download manager for android (1)

Source: Internet
Author: User

The Download manager is introduced in android 2.3 as a service to optimize the processing of long Download operations. Download Manager ensures that each Download is successful by handling HTTP links, monitoring link changes, and system restart.

Download an object;

Public void funclick (View view) {String serviceString = Context. DOWNLOAD_SERVICE; DownloadManager downloadManager; downloadManager = (DownloadManager) getSystemService (serviceString); Uri uri Uri = Uri. parse ("http://img00.hc360.com/it/201206/201206121034589404.jpg"); DownloadManager. request request = new Request (uri); long reference = downloadManager. enqueue (request );}

Remember to add permissions:


If you want to restrict Wi-Fi download, you can:

Request. setAllowedNetworkTypes (Request. NETWORK_WIFI );

Sometimes, if the data is not too big, we do not need to limit the need for WIFI to download, then you can use:

DownloadManager. getRecommendedMaxBytesOverMobile (getApplicationContext ());

He will return a maximum number of bytes recommended during mobile data connection upload and transmission to determine whether the download type should be limited to WI-FI.

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.