下载管理器进度在通知区域中不可见

时间:2017-05-05 15:29:16

标签: android android-download-manager

我正在使用下载管理器从网址下载文件。并且文件已成功下载。

问题

文件正在静默下载,通知区域中没有通知。

下载管理器在我的设备上运行android 6.0上显示通知(带进度条)。在我将设备更新到 android 7.0后,下载管理器不会在通知区域显示任何通知

这是我的代码

search

同时添加Uri uri = Uri.parse("file://" + destination); url = "http:....."; //Valid File URL //Set up download manager request DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setDescription("Downloading " + file_name); request.setTitle("My Downloader"); request.setDestinationUri(uri); //URI is valid //Start the download DownloadManager manager = (DownloadManager) getContext() .getSystemService(Context.DOWNLOAD_SERVICE); 对我的情况没有帮助。

构建信息

这是我的Gradle Build信息。

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);

2 个答案:

答案 0 :(得分:4)

我遇到了类似的问题,文件下载成功,但是在通知区域中看不到进度。

问题在于通知可见性。以下代码可以帮助我解决问题:

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

我希望这会有所帮助。

答案 1 :(得分:-1)

试试这个

DownloadPdf = (Button) findViewById(R.id.downloadpdf);
DownloadPdf.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

       File file = new File (Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS)+"/Pdf/" + "/" + name + ".pdf");
        if (file.exists()) {
            Toast.makeText(CatalogDetailActivity.this, "File Sudah ada", Toast.LENGTH_SHORT).show();
        } else {

      Download_Uri = Uri.parse(testing);
        DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
        request.setAllowedOverRoaming(false);
        request.setTitle("Downloading");
        request.allowScanningByMediaScanner();
        request.setDescription("Downloading");

        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/Pdf/" + "/" + name + ".pdf");
        refid = downloadManager.enqueue(request);
       }
    }
});