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