Android Download Manager

前端 未结 4 1274
慢半拍i
慢半拍i 2021-02-06 13:29

I think i have a rather simple question.

http://www.vogella.com/blog/2011/06/14/android-downloadmanager-example/

I have been following a tutorial in the above ur

4条回答
  •  自闭症患者
    2021-02-06 13:30

    You make sure external storage access is permitted by user for your app. Include this code for the download

    DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
         Uri uri = Uri.parse(url_string);
         DownloadManager.Request request = new DownloadManager.Request(uri);        
         request.setVisibleInDownloadsUi(true);        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        // include this line if permission has been granted by user to external directory
         request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());  
    // or this line if not yet granted
    request.setDestinationUri(Uri.parse("file://" + uri.getLastPathSegment());      
        Long reference = downloadManager.enqueue(request); 
    

提交回复
热议问题