DownloadManager.Request.setNotificationVisibility失败,jSecurityException:能见度无效值:2 [英] DownloadManager.Request.setNotificationVisibility fails with jSecurityException: invalid value for visibility: 2
问题描述
我试图使用下载管理器
在服务
类矿山的:
I'm trying to use DownloadManager
in a Service
class of mine:
DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
//imageUri is a valid Uri
Request downloadRequest= new Request(imageUri);
//without this line, it works
downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
//subpath is valid
downloadRequest.setDestinationInExternalFilesDir(this, null, subPath);
downloadManager.enqueue(downloadRequest);
没有 setNotificationVisibility
,这code效果很好。但是,它会显示一个通知,说我不想,因为我用这个$ C $下延迟加载图片的的ListView
。
Without setNotificationVisibility
, this code works well. But it displays a notification, that I don't want, because I use this code for lazy-loading images in a ListView
.
据我所知,这个通知可以隐藏以
I understand, this notification can be hidden with
downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
但在这种情况下,我的应用程序崩溃:
But in that case, my application crashes with:
2月2日至19号:24:24.055:E / AndroidRuntime(2572): java.lang.SecurityException异常:能见度值无效:二月2日至19号 02:24:24.055:E / AndroidRuntime(2572):在 android.os.Parcel.readException(Parcel.java:1327)2月19号02:24:24.055: E / AndroidRuntime(2572):在 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181) 2月2号至十九号:24:24.055:E / AndroidRuntime(2572):在 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) 2月2号至十九号:24:24.055:E / AndroidRuntime(2572):在 android.content.ContentProviderProxy.insert(ContentProviderNative.java:415) 2月2号至十九号:24:24.055:E / AndroidRuntime(2572):在 android.content.ContentResolver.insert(ContentResolver.java:730)02-19 02:24:24.055:E / AndroidRuntime(2572):在 android.app.DownloadManager.enqueue(DownloadManager.java:885)02-19 02:24:24.055:E / AndroidRuntime(2572):在 MyService.getImage(MyService.java:112)
02-19 02:24:24.055: E/AndroidRuntime(2572): java.lang.SecurityException: Invalid value for visibility: 2 02-19 02:24:24.055: E/AndroidRuntime(2572): at android.os.Parcel.readException(Parcel.java:1327) 02-19 02:24:24.055: E/AndroidRuntime(2572): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181) 02-19 02:24:24.055: E/AndroidRuntime(2572): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) 02-19 02:24:24.055: E/AndroidRuntime(2572): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:415) 02-19 02:24:24.055: E/AndroidRuntime(2572): at android.content.ContentResolver.insert(ContentResolver.java:730) 02-19 02:24:24.055: E/AndroidRuntime(2572): at android.app.DownloadManager.enqueue(DownloadManager.java:885) 02-19 02:24:24.055: E/AndroidRuntime(2572): at MyService.getImage(MyService.java:112)
请告诉我错 setNotificationVisibility
?哪有,我有通知?
Whats' wrong with setNotificationVisibility
? How can I had the notification?
推荐答案
您需要在清单按文档以下权限:
You need the following permission in the manifest as per documentation:
<uses-permission
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
这篇关于DownloadManager.Request.setNotificationVisibility失败,jSecurityException:能见度无效值:2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!