image_downloader
image_downloader copied to clipboard
mp4 video download crashes on Android 10
Issue
Hi, I'm trying to use this library for downloading images and videos. Both work perfectly on iOS but on Android 10 only image downloads work. When trying to download an mp4 I'm getting the following exception:
E/AndroidRuntime( 3639): FATAL EXCEPTION: main
E/AndroidRuntime( 3639): Process: com.myapp.android, PID: 3639
E/AndroidRuntime( 3639): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.myapp.android (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@ef6994e
E/AndroidRuntime( 3639): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1575)
E/AndroidRuntime( 3639): at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
E/AndroidRuntime( 3639): at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 3639): at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 3639): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 3639): at android.app.ActivityThread.main(ActivityThread.java:7710)
E/AndroidRuntime( 3639): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3639): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
E/AndroidRuntime( 3639): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
E/AndroidRuntime( 3639): Caused by: java.lang.IllegalArgumentException: MIME type video/mp4 cannot be inserted into content://media/external/images/media; expected MIME type under image/*
E/AndroidRuntime( 3639): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
E/AndroidRuntime( 3639): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
E/AndroidRuntime( 3639): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:495)
E/AndroidRuntime( 3639): at android.content.ContentResolver.insert(ContentResolver.java:1854)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.saveToDatabase(ImageDownloaderPlugin.kt:336)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.access$saveToDatabase(ImageDownloaderPlugin.kt:200)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:303)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:200)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:171)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:14)
E/AndroidRuntime( 3639): at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:33)
E/AndroidRuntime( 3639): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1560)
E/AndroidRuntime( 3639): ... 8 more
I/Process ( 3639): Sending signal. PID: 3639 SIG: 9
Lost connection to device.
This is how I'm calling the library:
ImageDownloader.downloadImage(url)
or ImageDownloader.downloadImage(url, outputMimeType: "video/mp4")
, both result in the same crash.
Example mp4 URL:
https://wikimediafoundation.org/wp-content/uploads/2021/01/WP20Anthem_English.mp4
Possible fix
We should be able to fix this by changing usages of MediaStore.Images.*
with MediaStore.Video.*
for video downloads.
e.g. here: https://github.com/ko2ic/image_downloader/blob/a4599be6b0c80bcb3fad168333c6e259ba46ccf4/android/src/main/kotlin/com/ko2ic/imagedownloader/ImageDownloaderPlugin.kt#L330
I am getting the same issue