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)