android studio中的DownloadManager无法下载pdf,显示无法下载项目

时间:2020-07-28 17:34:28

标签: android android-studio android-download-manager

我一直在Android Studio中使用downloadmanager下载pdf文件。它几乎适用于每个网址,但是 http://indiabudget.gov.in/doc/AFS/afs6.pdf 对我不起作用。 这是我的代码: /

/https://file-examples-com.github.io/uploads/2017/10/file-sample_150kB.pdf
//https://vpn.nic.in/resources/manuals/smc-update-error.pdf
        String url="http://indiabudget.gov.in/doc/AFS/afs6.pdf";
        DownloadManager.Request request=new DownloadManager.Request(Uri.parse(url));
        request.setTitle(title);
        request.setDescription("Downloading File....");
        request.allowScanningByMediaScanner();

        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
       request.setDestinationInExternalPublicDir(DIRECTORY_DOWNLOADS,title+".pdf");
       // request.setDestinationInExternalPublicDir("/data/data/com.example.indiabudgetgov/files/","a.pdf");
        //request.setDestinationInExternalFilesDir(getApplicationContext(),DIRECTORY_DOWNLOADS,"budgetspeech.pdf");
        DownloadManager downloadManager=(DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
        //request.setMimeType("application/pdf");
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
        Log.i("indiagov",String.valueOf(DIRECTORY_DOWNLOADS));
        downloadManager.enqueue(request);

我浏览了所有与downloadmamager相关的帖子,但仍然没有解决方案的提示。

0 个答案:

没有答案