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 116 forks source link

Error receiving broadcast Intent #14

Closed hninyuwai closed 5 years ago

hninyuwai commented 5 years ago

Hello, I am facing now with issue and I ran Nexus 5X Android P(emulator),please suggest me thanks. I faced this error for the first time permission and terminated the app but second is ok and image is downloaded.

E/AndroidRuntime( 6849): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg='applicationId' (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@6d1cd51 E/AndroidRuntime( 6849): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1341) E/AndroidRuntime( 6849): at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) E/AndroidRuntime( 6849): at android.os.Handler.handleCallback(Handler.java:873) E/AndroidRuntime( 6849): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 6849): at android.os.Looper.loop(Looper.java:164) E/AndroidRuntime( 6849): at android.app.ActivityThread.main(ActivityThread.java:6649) E/AndroidRuntime( 6849): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 6849): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/AndroidRuntime( 6849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826) E/AndroidRuntime( 6849): Caused by: java.io.FileNotFoundException: /storage/emulated/0/Download/2019-04-01.21.32.000 (Permission denied) E/AndroidRuntime( 6849): at java.io.FileInputStream.open0(Native Method) E/AndroidRuntime( 6849): at java.io.FileInputStream.open(FileInputStream.java:231) E/AndroidRuntime( 6849): at java.io.FileInputStream.(FileInputStream.java:165) E/AndroidRuntime( 6849): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:199) E/AndroidRuntime( 6849): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:152) E/AndroidRuntime( 6849): at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:98) E/AndroidRuntime( 6849): at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:12) E/AndroidRuntime( 6849): at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:31) E/AndroidRuntime( 6849): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1331) E/AndroidRuntime( 6849): ... 8 more I/Process ( 6849): Sending signal. PID: 6849 SIG: 9

ko2ic commented 5 years ago

@hninyuwai I confirmed to work under the same conditions(Nexus 5X Android P emulator).

I have two questions.

  1. Did this happen with this Plugin example?
  2. Did you get a dialog with permission to access Storage for the first time?
hninyuwai commented 5 years ago

Yes,it happens with plugin example too. I got a dialog permission for the first time but app is terminated with this error then I open the app again but image is downloaded and app is not terminated.Thanks

On Tue, Apr 2, 2019 at 6:51 AM koji ishii notifications@github.com wrote:

@hninyuwai https://github.com/hninyuwai I confirmed to work under the same conditions(Nexus 5X Android P emulator).

I have two questions.

  1. Did this happen with this Plugin example?
  2. Did you get a dialog with permission to access Storage for the first time?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ko2ic/image_downloader/issues/14#issuecomment-478794549, or mute the thread https://github.com/notifications/unsubscribe-auth/AeGsVEctqW9RkYowjed_Os-xTEW4ATrBks5vcqKJgaJpZM4cV9e- .

ko2ic commented 5 years ago

@hninyuwai It did not occur in my environment.
Does this happen with the current version (0.13.2)?

If you have not solved it yet, could you give me the result of the following command?

$ flutter doctor -v

kraster010 commented 5 years ago

It's happening also on my side.

i'm running 0.13.2 version.

this is crashing the app: $ ImageDownloader.downloadImage(api.getImageUrl(elem))

First it asks a runtime permissions to write on external storage and after you click OK the app crashes.

this is the exception:

info flutter.tools E/AndroidRuntime(21863): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=applicationId (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@956c9a3

$ flutter doctor -v

[✓] Flutter (Channel dev, v1.4.8, on Linux, locale en_US.UTF-8) • Flutter version 1.4.8 at /home/kunda/Libraries/flutter • Framework revision fbefd6b816 (8 days ago), 2019-04-01 10:58:30 -0700 • Engine revision a850016454 • Dart version 2.2.1 (build 2.2.1-dev.2.1 None)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at /home/kunda/Android/Sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-28, build-tools 28.0.3 • Java binary at: /home/kunda/Programmi/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01) • All Android licenses accepted.

[✓] Android Studio (version 3.3) • Android Studio at /home/kunda/Programmi/android-studio • Flutter plugin version 34.0.1 • Dart plugin version 182.5215 • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] IntelliJ IDEA Ultimate Edition (version 2019.1) • IntelliJ at /snap/intellij-idea-ultimate/133 ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • For information about installing plugins, see https://flutter.io/intellij-setup/#installing-the-plugins

[!] IntelliJ IDEA Ultimate Edition (version 2018.3) • IntelliJ at /snap/intellij-idea-ultimate/122 ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • For information about installing plugins, see https://flutter.io/intellij-setup/#installing-the-plugins

[✓] Connected device (2 available) • MI 5 • 5bbafb72 • android-arm64 • Android 8.0.0 (API 26) • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

Tried both MI 5 Device (phone) and Nexus 5 Emulator from android studio.

hninyuwai commented 5 years ago

my version and now after i tried android with native code and iOS used with this lib, it is ok. Thanks you for replying.

[✓] Flutter (Channel beta, v1.0.0, on Mac OS X 10.14.3 18D109, locale en-MM) • Flutter version 1.0.0 at /Users/yuwai/flutter • Framework revision 5391447fae (4 months ago), 2018-11-29 19:41:26 -0800 • Engine revision 7375a0f414 • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3) • Android SDK at /Users/yuwai/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-28, build-tools 28.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06) • All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices (Xcode 10.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 10.1, Build version 10B61 ✗ Verify that all connected devices have been paired with this computer in Xcode. If all devices have been paired, libimobiledevice and ideviceinstaller may require updating. To update with Brew, run: brew update brew uninstall --ignore-dependencies libimobiledevice brew uninstall --ignore-dependencies usbmuxd brew install --HEAD usbmuxd brew unlink usbmuxd brew link usbmuxd brew install --HEAD libimobiledevice brew install ideviceinstaller • ios-deploy 1.9.4 • CocoaPods version 1.5.2

[✓] Android Studio (version 3.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 31.1.1 • Dart plugin version 181.5656 • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Community Edition (version 2018.1.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 24.2.2 • Dart plugin version 181.4892.1

[✓] Connected device (2 available) • SM G532G • 92011da76c6e54c9 • android-arm • Android 6.0.1 (API 23) • Android SDK built for x86 • emulator-5554 • android-x86 • Android P (API 27) (emulator)

ko2ic commented 5 years ago

@kraster010 Could you paste your stacktrace?

And is api.getImageUrl(elem) correct URL returned?

kraster010 commented 5 years ago

I've tried it only on Android.

Basically a server send me a set of images link which i then try to download. here the snippet. there are about 10 images in the framePath array.

for(var elem in video.framePaths){
    try{
        await ImageDownloader.downloadImage(api.getImageUrl(elem));
    } catch(_) {
        print("can't download image $elem");
    }
 }

The links are only available for 5 minutes so if you try to get the image now you will get a 404. but when the link is valid and i try to download the image this stacktrace happens: (maybe it downloads 4 out 10 images then it crashes, sometimes 1 out 10, sometimes 2 out 10. but everytime the app crashes)

This is the stacktrace: 10:49:27.589 105 info flutter.tools D/image_downloader( 3777): RequestResult(id=22, remoteUri=https://mobile.powerseriesneogo.com/mobile-api/rest/session/56f18efb-b228-4e52-bbb6-8df301ee85bf/video/file/1221018012_1554837934000_12_10_1.jpg, localUri=file:///storage/emulated/0/Download/2019-04-10.10.49.039, mediaType=image/jpeg, totalSize=3434, title=2019-04-10.10.49.039, description=) 10:49:27.589 106 info flutter.tools D/AndroidRuntime( 3777): Shutting down VM 10:49:27.606 107 info flutter.tools E/AndroidRuntime( 3777): FATAL EXCEPTION: main 10:49:27.606 108 info flutter.tools E/AndroidRuntime( 3777): Process: com.dsc.powerneo, PID: 3777 10:49:27.606 109 info flutter.tools E/AndroidRuntime( 3777): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.dsc.powerneo (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@2a076ee 10:49:27.606 110 info flutter.tools E/AndroidRuntime( 3777): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1401) 10:49:27.606 111 info flutter.tools E/AndroidRuntime( 3777): at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) 10:49:27.606 112 info flutter.tools E/AndroidRuntime( 3777): at android.os.Handler.handleCallback(Handler.java:873) 10:49:27.606 113 info flutter.tools E/AndroidRuntime( 3777): at android.os.Handler.dispatchMessage(Handler.java:99) 10:49:27.606 114 info flutter.tools E/AndroidRuntime( 3777): at android.os.Looper.loop(Looper.java:193) 10:49:27.606 115 info flutter.tools E/AndroidRuntime( 3777): at android.app.ActivityThread.main(ActivityThread.java:6669) 10:49:27.606 116 info flutter.tools E/AndroidRuntime( 3777): at java.lang.reflect.Method.invoke(Native Method) 10:49:27.606 117 info flutter.tools E/AndroidRuntime( 3777): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 10:49:27.606 118 info flutter.tools E/AndroidRuntime( 3777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 10:49:27.606 119 info flutter.tools E/AndroidRuntime( 3777): Caused by: java.lang.IllegalStateException: newMimeType must not be null 10:49:27.606 120 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:223) 10:49:27.606 121 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:155) 10:49:27.606 122 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:125) 10:49:27.606 123 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:12) 10:49:27.606 124 info flutter.tools E/AndroidRuntime( 3777): at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:31) 10:49:27.606 125 info flutter.tools E/AndroidRuntime( 3777): at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391) 10:49:27.606 126 info flutter.tools E/AndroidRuntime( 3777): ... 8 more 10:49:27.606 127 info flutter.tools I/Process ( 3777): Sending signal. PID: 3777 SIG: 9

let me know if you need something more

ko2ic commented 5 years ago

@kraster010 Are you trying to save the video? It does not support.

kraster010 commented 5 years ago

no its not a video, its a set of 10 images coming from an IP camera. video.framePaths contain a list of url image links which i can get from the server (camera IP -> Server -> UserApp)

ko2ic commented 5 years ago

Oh, I'm sorry. Probably due to trying to get multiple files.

This is not yet supported but it may temporarily solve by the code below.

                RaisedButton(
                  onPressed: () async {
                    var list = Iterable<int>.generate(10).toList();
                    for (var _ in list) {
                      Future.delayed(Duration(seconds: 3)); // <- added
                      await _downloadImage();
                    }
                  },
                  child: Text("default destination"),
                ),
ko2ic commented 5 years ago

@kraster010 It was different from the original issue, so I made another issue. Please use this.