【问题标题】:How to programatically remove notification in download manager android如何以编程方式删除下载管理器android中的通知
【发布时间】:2018-08-03 07:20:45
【问题描述】:

我已经在一个活动中实现了 DownloadManager。下载工作正常。但是这个类会自动创建一个通知,它会留在状态栏中。有没有办法删除这个通知。下面是代码:

 Uri uri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setTitle(fileName);
    request.setDescription(fileName);
    request.setVisibleInDownloadsUi(false);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);

    firmwareZipPath = new File(Environment.getExternalStorageDirectory()
            + File.separator
            + Constants.TEST,
            type + ".tgz");

    request.setDestinationUri(Uri.fromFile(firmwareZipPath));
    downloadId = downloadManager.enqueue(request);

我尝试给request.setVisibleInDownloadsUi 提供虚假信息。仍然显示通知。

【问题讨论】:

    标签: android notifications download-manager


    【解决方案1】:

    来自official doc

    如果设置为 VISIBILITY_HIDDEN,则需要权限 android.permission.DOWNLOAD_WITHOUT_NOTIFICATION。

    所以需要给AndroidManifest.xml添加权限:

    <uses-permission
            android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    

    更多信息请查看official doc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 2017-10-11
      • 2016-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多