Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to pick image using image_picker plugin On Android 10 #40339

Closed
VickySalunkhe opened this issue Sep 12, 2019 · 33 comments
Closed

Fail to pick image using image_picker plugin On Android 10 #40339

VickySalunkhe opened this issue Sep 12, 2019 · 33 comments
Labels
a: release Challenges faced when attempting to productionize an app c: crash Stack traces logged to the console customer: crowd Affects or could affect many people, though not necessarily a specific customer. e: OS-version specific Affects only some versions of the relevant operating system p: image_picker The Image Picker plugin. package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version

Comments

@VickySalunkhe
Copy link

VickySalunkhe commented Sep 12, 2019

I am using the image_picker plugin in my app from last 5 months

there has been no code change since then but recently when I upgraded to flutter stable v1.9.1

I started getting this error whenever I tried to use the feature

When I click on button to pick image via gallery / camera
event is launched but it doesn't return any file with it
and there is no entry in log either

but when I try once more the button no longer works and errors are registered in the log

I tried FLUTTER CLEAN and changing the channel too but that too didnt help

** log **

> I/Timeline(12347): Timeline: Activity_launch_request time:323704530 intent:Intent { act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.google.android.packageinstaller (has extras) }
I/Timeline(12347): Timeline: Activity_launch_request time:323706693 intent:Intent { act=android.intent.action.GET_CONTENT typ=image/* }
E/flutter (12347): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(already_active, Image picker is already active, null)
E/flutter (12347): #0      StandardMethodCodec.decodeEnvelope 
package:flutter/…/services/message_codecs.dart:569
E/flutter (12347): #1      MethodChannel.invokeMethod 
package:flutter/…/services/platform_channel.dart:316
E/flutter (12347): <asynchronous suspension>
E/flutter (12347): #2      ImagePicker.pickImage 
package:image_picker/image_picker.dart:59
E/flutter (12347): <asynchronous suspension>
E/flutter (12347): #3      _CreateQuoteState._getImage 
package:Writco/…/CreatePost/create_quote.dart:746
E/flutter (12347): <asynchronous suspension>
E/flutter (12347): #4      _CreateQuoteState._imagePickDialog.<anonymous closure>.<anonymous closure> 
package:Writco/…/CreatePost/create_quote.dart:604
E/flutter (12347): #5      _InkResponseState._handleTap 
package:flutter/…/material/ink_well.dart:654
E/flutter (12347): #6      _InkResponseState.build.<anonymous closure> 
package:flutter/…/material/ink_well.dart:729
E/flutter (12347): #7      GestureRecognizer.invokeCallback 
package:flutter/…/gestures/recognizer.dart:182
E/flutter (12347): #8      TapGestureRecognizer._checkUp 
package:flutter/…/gestures/tap.dart:365
E/flutter (12347): #9      TapGestureRecognizer.handlePrimaryPointer 
package:flutter/…/gestures/tap.dart:275
E/flutter (12347): #10     PrimaryPointerGestureRecognizer.handleEvent 
package:flutter/…/gestures/recognizer.dart:455
E/flutter (12347): #11     PointerRouter._dispatch 
package:flutter/…/gestures/pointer_router.dart:75
E/flutter (12347): #12     PointerRouter.route 
package:flutter/…/gestures/pointer_router.dart:102
E/flutter (12347): #13     GestureBinding.handleEvent 
package:flutter/…/gestures/binding.dart:218
E/flutter (12347): #14     GestureBinding.dispatchEvent 
package:flutter/…/gestures/binding.dart:198
E/flutter (12347): #15     GestureBinding._handlePointerEvent 
package:flutter/…/gestures/binding.dart:156
E/flutter (12347): #16     GestureBinding._flushPointerEventQueue 
package:flutter/…/gestures/binding.dart:102
E/flutter (12347): #17     GestureBinding._handlePointerDataPacket 
package:flutter/…/gestures/binding.dart:86
E/flutter (12347): #18     _rootRunUnary  (dart:async/zone.dart:1136:13)
E/flutter (12347): #19     _CustomZone.runUnary  (dart:async/zone.dart:1029:19)
E/flutter (12347): #20     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:931:7)
E/flutter (12347): #21     _invoke1  (dart:ui/hooks.dart:263:10)
E/flutter (12347): #22     _dispatchPointerDataPacket  (dart:ui/hooks.dart:172:5)

flutter doctor

> Doctor summary (to see all details, run flutter doctor -v):
> [√] Flutter (Channel stable, v1.9.1+hotfix.2, on Microsoft Windows [Version 10.0.17763.678], locale en-US)
> [√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
> [√] Android Studio (version 3.4)
> [√] VS Code (version 1.38.0)
> [√] Connected device (1 available)
> 
> • No issues found!
@BondarenkoStas
Copy link

@VickySalunkhe Please provide a small self-contained app that demonstrates the problem. You can include small examples inline if they're enclosed by backticks, or just provide a public link to a github "gist" - https://gist.github.com/.

@BondarenkoStas BondarenkoStas added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 12, 2019
@PlymouthRock
Copy link

I have a similar problem. Image picker stopped returning images after upgrading to 1.9.

It works in debug mode, but not in release mode. Here's a simple test you can run that we used to duplicate the problem. We're running this on a Pixel 3A with Android 10.

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Image Picker',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Test(),
    );
  }
}

class Test extends StatefulWidget {
  Test({Key key}) : super(key: key);

  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {

  List<String> _images = new List<String>();

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: GridView.builder(
        itemCount: _images.length,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3,
        ),
        itemBuilder: (BuildContext context, int index) {
          
          return Container(
            padding: const EdgeInsets.all(2),
            child: Image.asset(_images[index], fit: BoxFit.cover)
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          ImagePicker.pickImage(source: ImageSource.gallery).then((image) {
            if (image != null) {
              setState(() {
                _images.add(image.path);
              });
            }
          });
        },
      ),  
    );
  }
}

@BondarenkoStas BondarenkoStas added p: image_picker The Image Picker plugin. plugin labels Sep 13, 2019
@VickySalunkhe
Copy link
Author

issue got solved
issue was caused because of flutter_upi library

but the point here to note is there were no related error messages being generated while either building the app or while runtime

I solved this issue by just removing the code/functionality step by step which I added in backwards manner.

you can close this issue but I think the text highlighted can play part which needs to be solved.

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 14, 2019
@BondarenkoStas
Copy link

Closing as asked, the issue is referenced to the similar one.

@VickySalunkhe
Copy link
Author

@VickySalunkhe Please provide a small self-contained app that demonstrates the problem. You can include small examples inline if they're enclosed by backticks, or just provide a public link to a github "gist" - https://gist.github.com/.

hi @BondarenkoStas is your app working with android 10, while using image_picker plugin

@jifferon
Copy link

In my case: do, it doesn't. Works fine with < 10 though

@theghostyced
Copy link

Same here, the event isnt triggered in my app

@Maadhav
Copy link

Maadhav commented Feb 8, 2020

Any Update?

@theghostyced
Copy link

So for me, turns out that i had another event listener on the button i was trying to use to trigger the image_picker, took of the listener and it worked for me

@VickySalunkhe VickySalunkhe changed the title Fail to pick image using image_picker plugin Fail to pick image using image_picker plugin On Android 10 Mar 4, 2020
@VickySalunkhe VickySalunkhe changed the title Fail to pick image using image_picker plugin On Android 10 Fail to pick image using image_picker plugin Mar 4, 2020
@VickySalunkhe
Copy link
Author

@egorikem
for many people this worked
try adding requestLegacyExternalStorage="true" under <Application> tag in Manifest file

well that didn't help me resolve the image_picker issue to pick image on Android 10 devices.

What I did is downgraded targetSdkVersion and compileSdkVersion to 28 from 29 I the gradle file
and that worked for me.

Meanwhile please Flutter team have a look at this issue as due to growing Android 10 devices count this issue is getting big day by day.

@TahaTesser TahaTesser changed the title Fail to pick image using image_picker plugin Fail to pick image using image_picker plugin On Android 10 Mar 13, 2020
@TahaTesser TahaTesser reopened this Mar 13, 2020
@TahaTesser TahaTesser added customer: crowd Affects or could affect many people, though not necessarily a specific customer. e: OS-version specific Affects only some versions of the relevant operating system c: crash Stack traces logged to the console a: release Challenges faced when attempting to productionize an app labels Mar 13, 2020
@xiaobeiy
Copy link

the same issue

@valterh4ck3r
Copy link

valterh4ck3r commented May 15, 2020

Switch to flutter channel stable and upgrade.

Works on channel stable.

@leszekkrol
Copy link

To sum up:

  • changing the version number from 28 to 29 does not correct the problem. even upgrade to 30...
  • the problem occurs in flutter version 1.19 and above

On the stable channel we have flutter versions 1.17.5 which unfortunately does not work with some libraries.

Example:
Because cached_network_image 2.3.0-rc requires Flutter SDK version >=1.19.0-2.0.pre <2.0.0 and no versions of cached_network_image match >2.3.0-rc <3.0.0, cached_network_image ^2.3.0-rc is forbidden.
So, because fanroom depends on cached_network_image ^2.3.0-rc, version solving failed.

Any ideas?

@just-kip
Copy link

just-kip commented Jul 19, 2020

To sum up:

  • changing the version number from 28 to 29 does not correct the problem. even upgrade to 30...
  • the problem occurs in flutter version 1.19 and above

On the stable channel we have flutter versions 1.17.5 which unfortunately does not work with some libraries.

Example:
Because cached_network_image 2.3.0-rc requires Flutter SDK version >=1.19.0-2.0.pre <2.0.0 and no versions of cached_network_image match >2.3.0-rc <3.0.0, cached_network_image ^2.3.0-rc is forbidden.
So, because fanroom depends on cached_network_image ^2.3.0-rc, version solving failed.

Any ideas?

Did you try upgrading android project to plugin api v2?

@leszekkrol
Copy link

@just-kip Tried, the same

@Sohi2795
Copy link

My better suggestion is to use your own channel to pick the image from native instead of using the third-party libraries, because sometimes you may get the plugin issues which will not be resolved and need to be waited until the plugin gets updated. Recently i faced the Permissions issue in flutter where i'm using permission_handler and the image_picker, the permission_handler i have used for microphone access, where as the image_picker will have their own permission checker. So when we include both the libraries in the project only one library will work because of the Override method of OnRequest and OnActivity.

The image_picker works for android 10 only in debug mode.

If anybody want i can provide the code for picking the image using own channel

@wijesijp
Copy link

I am having the same issue.
Is there a fix for this?

@PaccoreIT
Copy link

Im also facing the same issue. if any one having workaround for this issue?

@a-elhaddad
Copy link

Any fixes ? The image_picker works for android 10 only in debug mode ?

@leszekkrol
Copy link

@a-elhaddad Correct, works on debug mode

@rizalkotlin
Copy link

yes I experienced the same thing in Image_picker only works for android 10 in debug mode?

@DharmeshBasapati
Copy link

@Sohi2795 Can you please guide me how to pick the image from camera using platform channel?

@Sohi2795
Copy link

Sohi2795 commented Dec 22, 2020

@DharmeshBasapati First create a channel
MethodChannel _channel = const MethodChannel('channel_name');
Next Invoke the channel to call the function in native side(android/ios)
var image = await _channel.invokeMethod('camera');
configure the flutter engine in native, next you need to check for channel name('camera'). If matches then check for permissions(Note : Don't use multiple permission libraries, because of the conflits)

. Every time you need to send the result after invoking the channel, otherwise it will throws error.

    private fun checkPermissionCamera() {
            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), MY_PERMISSIONS_REQUESTS_CAMERA)
            } else if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), MY_PERMISSIONS_REQUESTS_CAMERA)
            } else if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    
                ActivityCompat.requestPermissions(activity, arrayOf(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), MY_PERMISSIONS_REQUESTS_CAMERA)
    
            } else{
                captureImage()
            }
        }

  private fun captureImage() {
          val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
          val file: File = CameraUtils.getOutputMediaFile(MEDIA_TYPE_IMAGE)
          if (file != null) {
              imageStoragePath = file.getAbsolutePath()
          }
          val fileUri: Uri = CameraUtils.getOutputMediaFileUri(applicationContext, file)
          intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri)
  
          // start the image capture Intent
          startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE)
      }

      In onActivityResult return result
      CameraUtils.refreshGallery(getApplicationContext(), imageStoragePath)
                          if(check(imageStoragePath)){
                              pendingHintResult?.success(imageStoragePath)
                          }else{
                              pendingHintResult?.success("denied")
                          }

@DharmeshBasapati
Copy link

@DharmeshBasapati First create a channel
MethodChannel _channel = const MethodChannel('channel_name');
Next Invoke the channel to call the function in native side(android/ios)
var image = await _channel.invokeMethod('camera');
configure the flutter engine in native, next you need to check for channel name('camera'). If matches then check for permissions(Note : Don't use multiple permission libraries, because of the conflits)

. Every time you need to send the result after invoking the channel, otherwise it will throws error.

    private fun checkPermissionCamera() {
            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), MY_PERMISSIONS_REQUESTS_CAMERA)
            } else if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), MY_PERMISSIONS_REQUESTS_CAMERA)
            } else if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    
                ActivityCompat.requestPermissions(activity, arrayOf(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), MY_PERMISSIONS_REQUESTS_CAMERA)
    
            } else{
                captureImage()
            }
        }

  private fun captureImage() {
          val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
          val file: File = CameraUtils.getOutputMediaFile(MEDIA_TYPE_IMAGE)
          if (file != null) {
              imageStoragePath = file.getAbsolutePath()
          }
          val fileUri: Uri = CameraUtils.getOutputMediaFileUri(applicationContext, file)
          intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri)
  
          // start the image capture Intent
          startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE)
      }

      In onActivityResult return result
      CameraUtils.refreshGallery(getApplicationContext(), imageStoragePath)
                          if(check(imageStoragePath)){
                              pendingHintResult?.success(imageStoragePath)
                          }else{
                              pendingHintResult?.success("denied")
                          }

Thanks for the detailed code. I will try to implement it and let you know.

@karambitmonger
Copy link

@Sohi2795 could you provide the code for custom image picker?

@Sohi2795
Copy link

@Sohi2795 could you provide the code for custom image picker?

@karambitmonger find the example https://github.com/Sohi2795/flutter_image_picker

@yannainghtun-mk
Copy link

Is there any fix? I am facing this issue.

@jeremiahseun
Copy link

What i did was to change the build Gradle to 3.5.0 in AndroidManifest.xml and the classpath and it worked for me.

I guess imagepicker haven't updated the package to the latest Android Gradle version.

@darshankawar
Copy link
Member

Hello Everyone,
I verified this issue going by the title (Fail to pick image using image_picker plugin On Android 10 ) on latest stable (1.22.6) using Samsung S10 device and official image_picker plugin repo. I was able to pick image from gallery as well as different options from drawer in debug and in release mode.

40339.mp4
flutter doctor -v

[✓] Flutter (Channel stable, 1.22.6, on Mac OS X 10.15.4 19E2269 darwin-x64, locale
    en-IN)
    • Flutter version 1.22.6 at /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision 9b2d32b605 (3 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.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • 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.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.9.3

[!] 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.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.18.1

[✓] Connected device (1 available)
    • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 10 (API 29)

! Doctor found issues in 1 category.

I am going ahead and closing this as not producible and probably fixed in latest plugin version, since it has gone through many bug fixes and features since this issue was filed.

Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.

@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label Feb 10, 2021
@michaelspeed
Copy link

for me this error still exist - using
• Flutter version 1.22.6 at /Users/michaelspeed/flutter • Framework revision 9b2d32b605 (4 weeks ago), 2021-01-22 14:36:39 -0800 • Engine revision 2f0af37152 • Dart version 2.10.5

@alexshikov
Copy link

What's the combination of version to make it work?

We do experience the problem still.

We have:

  • flutter: 1.22.6
  • image_picker: 0.6.7
  • shared_preferences: 0.5.8

We also tried:

  • image_picker: 0.6.5
  • shared_preferences: 0.5.12+4

No luck in release mode, we get MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

@github-actions
Copy link

github-actions bot commented Aug 3, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: release Challenges faced when attempting to productionize an app c: crash Stack traces logged to the console customer: crowd Affects or could affect many people, though not necessarily a specific customer. e: OS-version specific Affects only some versions of the relevant operating system p: image_picker The Image Picker plugin. package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

No branches or pull requests