ko2ic / image_downloader

Flutter plugin that downloads images and movies on the Internet and saves to Photo Library on iOS or specified directory on Android.
https://pub.dartlang.org/packages/image_downloader#-readme-tab-
MIT License
92 stars 115 forks source link

Crash on Android before SDK 25 #80

Open ra-develop opened 4 years ago

ra-develop commented 4 years ago

Crash on Android before SDK 25. Used code:

                  final imageId = await ImageDownloader.downloadImage(
                    memoryNotifier.memories[_memoriesId].image,
                  );
                  if (imageId == null) {
                    print(
                        "imageId == null: You not been granted permission for writing data to storage.");
                    showAlertBox(context,
                        "You not been granted permission for writing data to storage.");
                    return;
                  }

                  /* Below is a method of obtaining saved image information. */
//                  final fileName = await ImageDownloader.findName(imageId);
                  final path =
                      await ImageDownloader.findPath(imageId); // with file name
                  // final size = await ImageDownloader.findByteSize(imageId);
                  final mimeType = await ImageDownloader.findMimeType(imageId);

                  final typeOfShare =
                      mimeType.contains('image') ? "image" : "file";

Log: D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=null, mediaType=null, totalSize=-1, title=, description=) D/image_downloader(11530): 0 D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=null, mediaType=null, totalSize=-1, title=, description=) D/image_downloader(11530): 0 D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=null, mediaType=null, totalSize=-1, title=, description=) D/image_downloader(11530): 0 D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=file:///storage/sdcard/Download/2020-06-28.02.07.039, mediaType=image/jpeg, totalSize=-1, title=2020-06-28.02.07.039, description=) D/image_downloader(11530): 0 D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=file:///storage/sdcard/Download/2020-06-28.02.07.039, mediaType=image/jpeg, totalSize=-1, title=2020-06-28.02.07.039, description=) D/image_downloader(11530): 0 D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=file:///storage/sdcard/Download/2020-06-28.02.07.039, mediaType=image/jpeg, totalSize=189974, title=2020-06-28.02.07.039, description=) D/AndroidRuntime(11530): Shutting down VM E/AndroidRuntime(11530): FATAL EXCEPTION: main E/AndroidRuntime(11530): Process: com.personal.fluttermodule.host, PID: 11530 E/AndroidRuntime(11530): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.personal.fluttermodule.host (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@6ac4791 E/AndroidRuntime(11530): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:876) E/AndroidRuntime(11530): at android.os.Handler.handleCallback(Handler.java:739) E/AndroidRuntime(11530): at android.os.Handler.dispatchMessage(Handler.java:95) E/AndroidRuntime(11530): at android.os.Looper.loop(Looper.java:135) E/AndroidRuntime(11530): at android.app.ActivityThread.main(ActivityThread.java:5254) E/AndroidRuntime(11530): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(11530): at java.lang.reflect.Method.invoke(Method.java:372) E/AndroidRuntime(11530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) E/AndroidRuntime(11530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) E/AndroidRuntime(11530): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0 E/AndroidRuntime(11530): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426) E/AndroidRuntime(11530): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136) E/AndroidRuntime(11530): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50) E/AndroidRuntime(11530): at android.database.CursorWrapper.getString(CursorWrapper.java:114) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.saveToDatabase(ImageDownloaderPlugin.kt:349) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.access$saveToDatabase(ImageDownloaderPlugin.kt:200) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:303) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:200) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:171) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:14) E/AndroidRuntime(11530): at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:33) E/AndroidRuntime(11530): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:866) E/AndroidRuntime(11530): ... 8 more D/image_downloader(11530): RequestResult(id=37, remoteUri=https://placeimg.com/640/480/any?187531, localUri=file:///storage/sdcard/Download/2020-06-28.02.07.039, mediaType=image/jpeg, totalSize=189974, title=2020-06-28.02.07.039, description=) D/image_downloader(11530): 100 W/CursorWrapperInner(11530): Cursor finalized without prior close() I/Process (11530): Sending signal. PID: 11530 SIG: 9 Lost connection to device.