2015-02-06 48 views
0

当我尝试在setOnClickListener中使用DownLoadMaanger时,出现“DownLoad Manager未在android.app.downloadmanager中公开,但无法从外部包访问”的错误。 Android Studio不建议我可以做些什么来解决问题。请有人建议吗?DownLoad Manager在android.app.downloadmanager中不公开。无法从外部包访问

DownloadManager.Request request = new DownloadManager().Request(Uri.parse(pdfUrl)); 
      request.setDescription("pdf is downloading..."); 
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION); 
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "thanh_pdf"); 

      DownloadManager downloadManager = (DownloadManager)getActivity() 
        .getSystemService(Context.DOWNLOAD_SERVICE); 
      downloadManager.enqueue(request); 

回答

2

变化:

new DownloadManager().Request(Uri.parse(pdfUrl)); 

到:

new DownloadManager.Request(Uri.parse(pdfUrl)); 
相关问题