Android: How to use download manager class?

前端 未结 4 1842
再見小時候
再見小時候 2020-11-28 11:26

I want to download a binary file from a url. Is it possible to use the Android download manager class that I found here DownloadManager class?

4条回答
  •  半阙折子戏
    2020-11-28 11:57

    DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    Uri uri = Uri.parse("http://www.example.com/myfile.mp3");
    DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setTitle("My File");
    request.setDescription("Downloading");
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationUri(Uri.parse("file://" + folderName + "/myfile.mp3"));
    downloadmanager.enqueue(request);
    

提交回复
热议问题