如何以编程方式在Android下载管理器中删除通知

3

我在一个活动中实现了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 设置为 false。仍然显示通知。
1个回答

3

来自官方文档:

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

因此,您需要在AndroidManifest.xml中添加权限:

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

更多信息请查看官方文档


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接