android--call system Downloadmanager to download the file

Source: Internet
Author: User

There is a detailed comment in the code:

1  /**2 * This method is called the system's download manager3      */4      Public voiddownloadapk (Context context,string url) {5         /**6 * The reference variable returned here is a unique ID assigned by the system for the current download request .7 * We can regain this download task with this ID and do some of the things we want to do8 * or query the status of the download and cancel the download, etc.9          */TenUri uri = uri.parse (URL);//Download Connection OneManager = (Downloadmanager) context.getsystemservice (context. Download_service);//Get the system download management Arequestapk =NewDownloadmanager.request (URI);//Get connection Request Object -Requestapk.setallowednetworktypes (DownloadManager.Request.NETWORK_WIFI);//specify the network under which to download, here I specify a WiFi network -Requestapk.setdestinationinexternalpublicdir (Context.getpackagename () + "/mydownload", "xiaoyuantong.apk");//make a save path to the download file, I'll save it to the root directory theRequestapk.setvisibleindownloadsui (true);//set Display Download interface -Requestapk.allowscanningbymediascanner ();//indicates that Mediascanner is allowed to scan to this file, which is not allowed by default.  -Requestapk.settitle ("xxx update download");//to set up a notification bar in the download prompt message -Requestapk.setdescription ("xxx update download");//Instructions for setting up notification bar in the download +         LongDownloadid = Manager.enqueue (requestapk);//starts the download, which returns a unique ID assigned to the current download request by the system -}

android--call system Downloadmanager to download the file

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.