Android: calls the system DownLoadManager to download files. android calls the System camera.

Source: Internet
Author: User

Android: calls the system DownLoadManager to download files. android calls the System camera.

The Code contains detailed notes:

1/** 2 * This method calls the system's Download Manager 3 */4 public void downLoadApk (Context context, String url) {5/** 6 * here, the returned reference variable is a unique ID allocated by the system for the current download request. 7 * We can obtain the download task again through this ID, perform operations 8 * or query the download status and cancel the download. 9 */10 Uri uri = Uri. parse (url); // download connection 11 manager = (DownloadManager) context. getSystemService (context. DOWNLOAD_SERVICE); // obtain the system download management 12 requestApk = new DownloadManager. request (uri); // get the connection Request object 13 reques TApk. setAllowedNetworkTypes (DownloadManager. request. NETWORK_WIFI); // specify the network under which the download is made. Here I specify the WIFI network 14 requestApk. setDestinationInExternalPublicDir (context. getPackageName () + "/myDownLoad", "xiaoyuantong.apk"); // specify the path to save the downloaded file. Save it to the root directory 15 requestApk. setVisibleInDownloadsUi (true); // set to display the download interface 16 requestApk. allowScanningByMediaScanner (); // indicates that MediaScanner is allowed to scan this file, which is not allowed by default. 17 requestApk. setTitle ("xxx update and download"); // sets the message 18 requestApk in the notification bar during download. setDescription ("xxx update and download"); // you can specify 19 long downLoadId = manager. enqueue (requestApk); // starts the download. This method returns a unique ID20 allocated by the system for the current download request}

 

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.