Skip to content

[image_picker] Image picker returns null when selecting image from other apps when using singleInstance #76856

Description

@DomantasZav

Steps to Reproduce

This code snippet returns null only when selecting image from Google Photos:

await ImagePicker().getImage(
      source: ImageSource.gallery,
      imageQuality: 70,
      maxWidth: 2048,
      maxHeight: 2048,
    );

And I get this message in log cat:

E/UpdateManager.Error( 5083): com.google.android.play.core.install.InstallException: Install Error(-3): The API is not available on this device. (https://developer.android.com/reference/com/google/android/play/core/install/model/InstallErrorCode#ERROR_API_NOT_AVAILABLE)
[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
    • Flutter version 1.22.6 at C:\Users\Domantas\AppData\Local\flutter
    • Framework revision 9b2d32b605 (5 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\Domantas\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[!] VS Code, 64-bit edition (version 1.35.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
    • motorola one vision (mobile) • ZY3265BDQZ • android-arm64 • Android 10 (API 29)

! Doctor found issues in 2 categories.

Activity

  1. TahaTesser commented on Feb 26, 2021

    @TahaTesser
    Contributor

    Hi @DomantasZav
    Can you please try a different device? Make sure you're using the latest stable `image_picker: ^0.6.7+22
    I can't reproduce it on a Oneplus or Realme device

    code runnable sample
    import 'package:flutter/material.dart';
    import 'package:image_picker/image_picker.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Material App',
          theme: ThemeData.dark(),
          home: Home(),
        );
      }
    }
    
    class Home extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Material App Bar'),
          ),
          body: Center(
            child: Container(
              child: Text('Hello World'),
            ),
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () async {
              final file = await ImagePicker().getImage(
                source: ImageSource.gallery,
                imageQuality: 70,
                maxWidth: 2048,
                maxHeight: 2048,
              );
    
              print(file.path);
            },
          ),
        );
      }
    }
    

    Printing path of the picked file

    D/ActivityThread(19231): pid:19231 tid:19231 doframe Callback
    I/flutter (19231): /storage/emulated/0/Android/data/com.example.stable_flutter/files/Pictures/scaled_image_picker7560935096891424193.jpg
    flutter doctor -v
    [✓] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
        • Flutter version 1.22.6 at C:\Users\Taha\Code\flutter_stable
        • Framework revision 9b2d32b605 (5 weeks ago), 2021-01-22 14:36:39 -0800
        • Engine revision 2f0af37152
        • Dart version 2.10.5
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at C:\Users\Taha\Code\SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = C:\Users\Taha\Code\SDK
        • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [!] Android Studio (version 4.1.0)
        • Android Studio at C:\Users\Taha\Code\android-studio
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [✓] VS Code (version 1.53.2)
        • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.19.0
    
    [✓] Connected device (2 available)
        • IN2011 (mobile)                    • c9d8ee0c      • android-arm64 • Android 11 (API 30)
        • Android SDK built for x86 (mobile) • emulator-5554 • android-x86   • Android 10 (API 29) (emulator)
    
    ! Doctor found issues in 1 category.

    Thank you

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 26, 2021
  3. DomantasZav commented on Mar 1, 2021

    @DomantasZav
    Author

    Found the issue:
    It only happens on android devices and if launchMode in AndroidManifest is set to singleInstance
    The error I provided was caused by something else.
    So there is no indication of error. It just returns null.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 1, 2021
  5. changed the title [-][image_picker] Image picker returns null when selecting image from Google Photos[/-] [+][image_picker] Image picker returns null when selecting image from Google Photos with launchMode="singleInstance" [/+] on Mar 2, 2021
  6. TahaTesser commented on Mar 2, 2021

    @TahaTesser
    Contributor

    Hi @DomantasZav
    Thanks for the details, I can reproduce it with singleIntance

    logs
    Launching lib/main.dart on IN2011 in debug mode...
     package:triage/main.dart
    ✓ Built build/app/outputs/flutter-apk/app-debug.apk.
    W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e
    W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e
    Connecting to VM Service at ws://127.0.0.1:51314/6OwUI-aX26c=/ws
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true
    W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e
    W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e
    D/ActivityThread(12154): pid:12154 tid:12154 doframe Callback
    D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2
    D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355
    D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2
    D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355
    D/DecorView(12154): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@480458[MainActivity]
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=true inTouchMode=true
    D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2
    D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355
    W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e
    W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true
    W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e
    W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e
    D/DecorView(12154): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@480458[MainActivity]
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=true inTouchMode=true
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true
    D/ActivityThread(12154): pid:12154 tid:12154 doframe Callback
    E/flutter (12154): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'path' was called on null.
    E/flutter (12154): Receiver: null
    E/flutter (12154): Tried calling: path
    �[38;5;244mE/flutter (12154): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)�[39;49m
    �[38;5;248mE/flutter (12154): #1      Home.build.<anonymous closure>�[39;49m
     package:triage/main.dart
    E/flutter (12154): <asynchronous suspension>
    �[38;5;248mE/flutter (12154): #2      Home.build.<anonymous closure> (package:triage/main.dart)�[39;49m
     package:triage/main.dart
    �[38;5;244mE/flutter (12154): #3      _InkResponseState._handleTap�[39;49m
     package:flutter/…/material/ink_well.dart
    �[38;5;244mE/flutter (12154): #4      _InkResponseState.build.<anonymous closure>�[39;49m
     package:flutter/…/material/ink_well.dart
    �[38;5;244mE/flutter (12154): #5      GestureRecognizer.invokeCallback�[39;49m
     package:flutter/…/gestures/recognizer.dart
    �[38;5;244mE/flutter (12154): #6      TapGestureRecognizer.handleTapUp�[39;49m
     package:flutter/…/gestures/tap.dart
    �[38;5;244mE/flutter (12154): #7      BaseTapGestureRecognizer._checkUp�[39;49m
     package:flutter/…/gestures/tap.dart
    �[38;5;244mE/flutter (12154): #8      BaseTapGestureRecognizer.handlePrimaryPointer�[39;49m
     package:flutter/…/gestures/tap.dart
    �[38;5;244mE/flutter (12154): #9      PrimaryPointerGestureRecognizer.handleEvent�[39;49m
     package:flutter/…/gestures/recognizer.dart
    �[38;5;244mE/flutter (12154): #10     PointerRouter._dispatch�[39;49m
     package:flutter/…/gestures/pointer_router.dart
    �[38;5;244mE/flutter (12154): #11     PointerRouter._dispatchEventToRoutes.<anonymous closure>�[39;49m
     package:flutter/…/gestures/pointer_router.dart
    �[38;5;244mE/flutter (12154): #12     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)�[39;49m
    �[38;5;244mE/flutter (12154): #13     PointerRouter._dispatchEventToRoutes�[39;49m
     package:flutter/…/gestures/pointer_router.dart
    �[38;5;244mE/flutter (12154): #14     PointerRouter.route�[39;49m
     package:flutter/…/gestures/pointer_router.dart
    �[38;5;244mE/flutter (12154): #15     GestureBinding.handleEvent�[39;49m
     package:flutter/…/gestures/binding.dart
    �[38;5;244mE/flutter (12154): #16     GestureBinding.dispatchEvent�[39;49m
     package:flutter/…/gestures/binding.dart
    �[38;5;244mE/flutter (12154): #17     RendererBinding.dispatchEvent�[39;49m
     package:flutter/…/rendering/binding.dart
    �[38;5;244mE/flutter (12154): #18     GestureBinding._handlePointerEvent�[39;49m
     package:flutter/…/gestures/binding.dart
    �[38;5;244mE/flutter (12154): #19     GestureBinding._flushPointerEventQueue�[39;49m
     package:flutter/…/gestures/binding.dart
    �[38;5;244mE/flutter (12154): #20     GestureBinding._handlePointerDataPacket�[39;49m
     package:flutter/…/gestures/binding.dart
    �[38;5;244mE/flutter (12154): #21     _rootRunUnary (dart:async/zone.dart:1206:13)�[39;49m
    �[38;5;244mE/flutter (12154): #22     _CustomZone.runUnary (dart:async/zone.dart:1100:19)�[39;49m
    �[38;5;244mE/flutter (12154): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)�[39;49m
    �[38;5;244mE/flutter (12154): #24     _invoke1 (dart:ui/hooks.dart:265:10)�[39;49m
    �[38;5;244mE/flutter (12154): #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)�[39;49m
    E/flutter (12154):
    D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2
    D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355
    D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2
    D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355
    D/DecorView(12154): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@480458[MainActivity]
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=true inTouchMode=true
    W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e
    W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e
    D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true
    
    flutter doctor -v
    [✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.2 20D80 darwin-x64, locale
        en-GB)
        • Flutter version 1.22.6 at /Users/tahatesser/Code/flutter_stable
        • Framework revision 9b2d32b605 (5 weeks ago), 2021-01-22 14:36:39 -0800
        • Engine revision 2f0af37152
        • Dart version 2.10.5
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Volumes/Extreme/SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = /Volumes/Extreme/SDK
        • Java binary at: /Applications/Android
          Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.4)
        • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
        • Xcode 12.4, Build version 12D4e
        • CocoaPods version 1.10.1
    
    [!] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6915495)
    
    [✓] VS Code (version 1.53.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.20.0
    
    [✓] Connected device (1 available)
        • IN2011 (mobile) • c9d8ee0c • android-arm64 • Android 11 (API 30)
    
    ! Doctor found issues in 1 category.
  7. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    platform-androidAndroid applications specifically
    and removed
    in triagePresently being triaged by the triage team
    on Mar 2, 2021
  8. added
    P2Important issues not at the top of the work list
    on Mar 4, 2021
  9. 16 remaining items

  10. changed the title [-][image_picker] Image picker returns null when selecting image from Google Photos with launchMode="singleInstance" [/-] [+][image_picker] Image picker returns `null` when selecting image from other apps[/+] on Feb 6, 2023
  11. TahaTesser commented on Feb 6, 2023

    @TahaTesser
  12. JeroenWeener commented on Mar 28, 2023

    @JeroenWeener

    I've been investigating the issue thoroughly. These are my findings.

    The issue occurs when the following conditions are met:

    • The activity in the Android manifest runs in launchMode: singleInstance,
    • The Intent.GET_CONTENT intent is used to open the native image picker application,
    • The user selects a file from Google Photos.

    I found that when these steps are taken, the onActivityResult function is called with a result code of RESULT_CANCELED instead of RESULT_OK.

    I created a basic native Android app to test whether this also happens on Android-only, as it could potentially be caused by the way Flutter uses the activities. The native app contains the basic activity from the template. On clicking the FAB, I start the image picker activity using the Intent.ACTION_GET_CONTENT intent.

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intent, 1);
    

    This all goes well. Then I update the manifest to use android:launchMode="singleInstance". Now, when opening the file picker and selecting a file from Google Photos, I receive a result code RESULT_CANCELED.

    This leads me to believe that this issue is a bug in the Android Image Picker.

  13. stuartmorgan-g commented on Apr 13, 2023

    @stuartmorgan-g
    Contributor

    This leads me to believe that this issue is a bug in the Android Image Picker.

    Based on further investigation, it looks like this is expected behavior rather than a bug, as described here. If the calling app forbids other activities it its task, then it can't get results from other activities.

    We can document this in the plugin's README to help avoid people being surprised by it.

  14. larssn commented on Apr 13, 2023

    @larssn
  15. changed the title [-][image_picker] Image picker returns `null` when selecting image from other apps[/-] [+][image_picker] Image picker returns `null` when selecting image from other apps when using `singleInstance`[/+] on Apr 13, 2023
  16. stuartmorgan-g commented on Apr 13, 2023

    @stuartmorgan-g
  17. github-actions commented on May 8, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions