java.lang.IllegalArgumentException:尝试打开下载的图像时未知的URI

问题描述

点击通知时,我无法打开通过DownloadManager下载的图像。

这是可重复的:
我使用DownloadManager从网络下载图像。
然后,当我单击“关于此下载的通知”并且OS出现一个对话框时,我可以选择“应用程序”以打开下载的图像,但是当我选择任何应用程序时,它们都不起作用。
例如,使用Google相册打开时,我在Logcat中看到此错误。

E/DatabaseUtils: Writing exception to parcel
    java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/12322
        at com.android.providers.downloads.DownloadProvider.query(DownloadProvider.java:1298)
        at android.content.ContentProvider.query(ContentProvider.java:1379)
        at android.content.ContentProvider.query(ContentProvider.java:1475)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:278)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
        at android.os.Binder.execTransactInternal(Binder.java:1154)
        at android.os.Binder.execTransact(Binder.java:1123)

在Android 11上重现,在以前的版本中一切正常。
检查文件系统时,映像位于Downloads文件夹中

我正在使用此代码下载图像

val downloadService: DownloadManager = activity.getSystemService(DOWNLOAD_SERVICE) as val downloadService: DownloadManager = activity.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
downloadService.enqueue(DownloadManager.Request(attachment.getAttachmentUri())
        .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
        .setAllowedOverRoaming(false)
        .setTitle(title)
        .setDescription("Downloading attachments")
        .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,title)
        .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
)

Pixel3a Android 11上进行了测试
targetSdkVersion 30
compileSdkVersion 30

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...