微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。