我在一个活动中实现了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
设置为假。仍然显示通知。
答案 0 :(得分:0)
来自official doc:
如果设置为VISIBILITY_HIDDEN,则需要权限 android.permission.DOWNLOAD_WITHOUT_NOTIFICATION。
因此,您需要向AndroidManifest.xml添加权限:
<uses-permission
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
有关更多信息,请检查official doc