How to use built-in download manager on Android

后端 未结 3 1021
-上瘾入骨i
-上瘾入骨i 2021-02-06 10:26

I want to develop an application for the android platform that can download some files from my server.

How can i use android\'s download manager like it is used in the A

3条回答
  •  离开以前
    2021-02-06 10:52

    Use this class for downloading any file using download manager

      public class DLManager {
     @SuppressLint("NewApi")
     public static void useDownloadManager(String url, String name, Context c) {
      DownloadManager dm = (DownloadManager) c
        .getSystemService(Context.DOWNLOAD_SERVICE);
      DownloadManager.Request dlrequest = new DownloadManager.Request(
        Uri.parse(url));
      dlrequest
        .setAllowedNetworkTypes(
          DownloadManager.Request.NETWORK_WIFI
            | DownloadManager.Request.NETWORK_MOBILE)
        .setTitle("Title")
        .setDescription("Downloading in Progress..")
        .setDestinationInExternalPublicDir("Directory_name", name + ".jpg")
        .allowScanningByMediaScanner();
    
      dm.enqueue(dlrequest);
    
     }
    }
    

提交回复
热议问题