我已经在 Activity 中实现了 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。仍然显示通知。
最佳答案
来自official doc :
If set to VISIBILITY_HIDDEN, this requires the permission android.permission.DOWNLOAD_WITHOUT_NOTIFICATION.
所以需要在AndroidManifest.xml中添加权限:
<uses-permission
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
欲了解更多信息,请查看official doc
关于android - 如何以编程方式删除下载管理器android中的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51667274/