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.