How to Enable Android Download Manager

前端 未结 4 1811
不思量自难忘°
不思量自难忘° 2020-12-23 14:04

I\'m using Android Download Manager to download list of files. Lately I came across a crash report saying

Unknown java.lang.IllegalArgumentException: Unknown

4条回答
  •  攒了一身酷
    2020-12-23 14:32

    May be it's help to you.

    downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
       DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
       //Restrict the types of networks over which this download may proceed.
       request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
       //Set whether this download may proceed over a roaming connection.
       request.setAllowedOverRoaming(false);
       //Set the title of this download, to be displayed in notifications (if enabled).
       request.setTitle("My Data Download");
       //Set a description of this download, to be displayed in notifications (if enabled)
       request.setDescription("Android Data download using DownloadManager.");
       //Set the local destination for the downloaded file to a path within the application's external files directory
       request.setDestinationInExternalFilesDir(this,Environment.DIRECTORY_DOWNLOADS,"CountryList.json");
    
       //Enqueue a new download and same the referenceId
       downloadReference = downloadManager.enqueue(request);
    

    http://www.mysamplecode.com/2012/09/android-downloadmanager-example.html

提交回复
热议问题