I can't open image downloaded with DownloadManager
when clicking on a notification.
This is how it's reproducible:
I download an image from network using DownloadManager
.
Then when I click on Notification about this download and OS shows me a dialog where I can choose Application to open downloaded image, but when I pick any application, none of them work.
For example, when opening with Google Photos I see this error in 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)
This reproduces on Android 11, on previous version everything works well.
When checking the filesystem the image is there in Downloads
folder
I'm using this code for downloading images
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)
)
Tested on Pixel3a Android 11
targetSdkVersion 30
compileSdkVersion 30