Android Download Manager (1)

Source: Internet
Author: User

Download Manager was introduced in Android 2.3. As a service to optimize the processing of long-time download operations. Download Manager ensures that every download succeeds by handling HTTP links, monitoring link changes, and system startup.

Download the file;

public void Funclick (view view) {String servicestring = Context.download_service;downloadmanager Downloadmanager; Downloadmanager = (Downloadmanager) getsystemservice (servicestring); Uri uri = uri.parse ("http://img00.hc360.com/it/201206/201206121034589404.jpg");D ownloadmanager.request Request = new Request (URI); Long reference = Downloadmanager.enqueue (request);}

Remember to add permissions:

<uses-permission android:name= "Android.permission.INTERNET"/>

Suppose you want to limit the download to WiFi, you can:

Request.setallowednetworktypes (Request.network_wifi);

Sometimes assuming that the data is not too large, we do not have to limit the ability to download the WiFi competency, which can be used:

Downloadmanager.getrecommendedmaxbytesovermobile (Getapplicationcontext ());

He will determine whether the download type should be limited to Wi-Fi by returning a maximum number of bytes recommended when transmitting on a mobile data connection.

Android Download Manager (1)

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.