我已经在一个活动中实现了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
加假。仍然显示通知。
来自官方文档:
如果设置为VISIBILITY_HIDDEN,则需要权限android.permission.DOWNLOAD_WITHOUT_NOTIFICATION.
因此您需要向AndroidManifest.xml添加权限:
<uses-permission
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
欲了解更多信息,请查看官方文档