DownloadManager.Request.setNotificationVisibility 失败并出现 SecurityException:可见性值无效:2
我正在尝试在我的 Service
类中使用 DownloadManager
:
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
,此代码可以正常工作。但它显示了一个我不想要的通知,因为我使用此代码在 ListView
中延迟加载图像。
据我了解,可以隐藏此通知,
downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
但在这种情况下,我的应用程序会崩溃:
02-19 02:24:24.055: E/AndroidRuntime(2572): java.lang.SecurityException:可见性值无效:2 02-19 02:24:24.055: E/AndroidRuntime(2572): 在 android.os.Parcel.readException(Parcel.java:1327) 02-19 02:24:24.055: E/Android运行时(2572):位于 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181) 02-19 02:24:24.055: E/AndroidRuntime(2572): 在 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) 02-19 02:24:24.055: E/AndroidRuntime(2572): 在 android.content.ContentProviderProxy.insert(ContentProviderNative.java:415) 02-19 02: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)
setNotificationVisibility
有什么问题吗?我怎样才能收到通知?
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);
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:
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)
Whats' wrong with setNotificationVisibility
? How can I had the notification?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据文档,您需要清单中的以下权限:
注意
大多数清单权限将由 Android Studio 自动完成,但这不会自动完成。
You need the following permission in the manifest as per documentation:
Note
Most of the manifest permissions will be autocompleted by Android Studio, but this will not be auto-completed.
但还需要将该权限添加到 rn-fetch-blob 的清单中,但其中未给出。
but also need to add that permission to rn-fetch-blob's manifest that is not given in it.