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

On Android Plugin crashes using FlutterFragmentActivity #70

Open shavyg2 opened 4 years ago

shavyg2 commented 4 years ago

https://github.com/ko2ic/image_downloader/blob/master/android/src/main/kotlin/com/ko2ic/imagedownloader/ImageDownloaderPermissionListener.kt#L13

The issue is on this line, the number needs to fit within 16 bits so 0 - 65535, while the library is using 2578166

Question, does that number really matter or just needs to be a unique number?

The actual error is below

E/MethodChannel#plugins.ko2ic.com/image_downloader(14041): Failed to handle method call
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041): java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at androidx.fragment.app.FragmentActivity.checkForValidRequestCode(FragmentActivity.java:715)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at androidx.fragment.app.FragmentActivity.validateRequestPermissionsRequestCode(FragmentActivity.java:730)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:500)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at com.ko2ic.imagedownloader.ImageDownloaderPermissionListener.alreadyGranted(ImageDownloaderPermissionListener.kt:46)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at com.ko2ic.imagedownloader.ImageDownloaderPlugin.onMethodCall(ImageDownloaderPlugin.kt:65)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.ko2ic.com/image_downloader(14041):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
shavyg2 commented 4 years ago

If this is cool and you don't mind a pull request, I can do that too, really want to get this fix working. Thx