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

PlatformException(no_available_camera, No cameras available for taking pictures., null) #62669

Closed
krupalbhardiya opened this issue Jul 31, 2020 · 19 comments

Comments

@krupalbhardiya
Copy link

krupalbhardiya commented Jul 31, 2020

Steps to Reproduce

Taking pictures using camera crashes the Plugin (Image Picker by Flutter)

final pickedFile = await _picker.getImage(source: ImageSource.camera);

This plugin works in Emulator and Physical device with Android API <=29.

On Android Platform API 30, the plugin crashed with no available cameras exception.

I've used the system default camera app in Android API 30 and is opens up the camera and captures the image on the other hand, plugin shows exception of no cameras available for taking pictures.
All Runtime permissions are allowed and static manifest permissions are also declared.

Expected results:
Open Camera and Take picture from system default Camera App.

Actual results:
PlatformException(no_available_camera, No cameras available for taking pictures., null)

Logs PlatformException(no_available_camera, No cameras available for taking pictures., null)

[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18363.720], locale en-US)
• Flutter version 1.17.5 at D:\flutter_sdk
• Framework revision 8af6b2f (4 weeks ago), 2020-06-30 12:53:55 -0700
• Engine revision ee76268252
• Dart version 2.8.4

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at D:\android_sdk
• Platform android-30, build-tools 30.0.1
• ANDROID_HOME = D:\android_sdk
• 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)
X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions.

[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code, 64-bit edition (version 1.47.3)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.12.2

[√] Connected device (1 available)
• sdk gphone x86 64 • emulator-5554 • android-x64 • Android 11 (API 30) (emulator)

@darshankawar
Copy link
Member

Hi @krupalbhardiya,
I tried to replicate the issue on latest master and was able to successfully capture image from emulator's camera.
I tested on Pixel 3a emulator with api 30.

62669_1
62669

I used image_picker plugin's official example as a code sample.

@darshankawar darshankawar added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Aug 3, 2020
@krupalbhardiya
Copy link
Author

@darsh

Hi @krupalbhardiya,
I tried to replicate the issue on latest master and was able to successfully capture image from emulator's camera.
I tested on Pixel 3a emulator with api 30.

62669_1
62669

I used image_picker plugin's official example as a code sample.

@darshankawar this code runs well in debug builds but it crashes the App in release build. App can't even start. It crashes from the start. So I have to remove the whole code in order to start the App.

@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 Aug 8, 2020
@darshankawar
Copy link
Member

Hi @krupalbhardiya,
Can you try to upgrade your flutter stable version to latest and see if you experience the same issue ?
Thanks.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 10, 2020
@krupalbhardiya
Copy link
Author

@darshankawar should i switch to master branch ?

@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 Aug 10, 2020
@krupalbhardiya
Copy link
Author

@darshankawar after switching to master branch and creating the release build variant of the App no longer crashes the App.

@Knupper
Copy link

Knupper commented Aug 24, 2020

@darshankawar i have tried your solution, but i get the same error as @krupalbhardiya . Are there other solutions?

@krupalbhardiya
Copy link
Author

@Knupper , issue is resolved in master branch. you can switch to master branch of flutter or wait till the latest version is available in stable branch.

@Knupper
Copy link

Knupper commented Aug 24, 2020

@krupalbhardiya i switched to the master branch, but have still the same output. When i start the ImagePicker with picker.getImage(source: ImageSource.gallery) it works fine, but when i change the source to ImageSource.camera it crashs.

E/flutter ( 5719): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(no_available_camera, No cameras available for taking pictures., null)
E/flutter ( 5719): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:572:7)
E/flutter ( 5719): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:161:18)
E/flutter ( 5719): <asynchronous suspension>
E/flutter ( 5719): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
E/flutter ( 5719): #3      MethodChannelImagePicker.pickImagePath (package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart:62:21)
E/flutter ( 5719): #4      MethodChannelImagePicker.pickImage (package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart:30:25)
E/flutter ( 5719): #5      ImagePicker.getImage (package:image_picker/image_picker.dart:101:21)
E/flutter ( 5719): #6      TestView._selectNewProfileImage (package:mytest/widgets/test.dartt:23:34)
E/flutter ( 5719): <asynchronous suspension>
E/flutter ( 5719): #7      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
E/flutter ( 5719): #8      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter ( 5719): #9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
E/flutter ( 5719): #10     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
E/flutter ( 5719): #11     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
E/flutter ( 5719): #12     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:256:7)
E/flutter ( 5719): #13     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:158:27)
E/flutter ( 5719): #14     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:224:20)
E/flutter ( 5719): #15     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
E/flutter ( 5719): #16     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
E/flutter ( 5719): #17     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
E/flutter ( 5719): #18     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
E/flutter ( 5719): #19     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5719): #20     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5719): #21     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5719): #22     _invoke1 (dart:ui/hooks.dart:267:10)
E/flutter ( 5719): #23     _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)

Switching to the master/beta channel have not changed anything. Any other ideas are welcome :)

@Knupper
Copy link

Knupper commented Aug 28, 2020

I took another look into it, the example project works for me, but when i change the targetSdkVersion and compileSdkVersion to 30 there as well, i get the posted error. @krupalbhardiya maybe this helps you as well?

@farazk86
Copy link

farazk86 commented Sep 8, 2020

I had the same error, my compileSdkVersion and targetSdkVersion were both 30.

Changing these to 29 fixed the issue for me.

@ciprig
Copy link

ciprig commented Sep 23, 2020

The issue does still reproduce with targetSdkVersion 30 on Flutter Channel beta, 1.22.0-12.1.pre.
With targetSdkVersion 29 and compileSdkVersion 30 it's working.

@darshankawar
Copy link
Member

This seems to be an issue with targeting api version to 30.
See this comment and related documentation on accessing apps targeted to api 30.
And according to the same comment, please try to add
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> in manifest and see if it resolves your issue
Thanks.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 28, 2020
@Knupper
Copy link

Knupper commented Oct 3, 2020

@darshankawar i have tried it today, with this permission it works fine with tagetSdk30.

@darshankawar
Copy link
Member

@Knupper
Thanks for confirming. With that said, I am going ahead and closing this issue.
@ciprig , @farazk86 Please see above comment and solution, try again and see if it works for you.
If you still see the issue, please write in comments and I'll reopen.
Thanks.

@darshankawar darshankawar removed in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Oct 5, 2020
@Zony-Zhao
Copy link

@darshankawar You are A LIFE-SAVER! Only way to compatible with two packages 'geolocator' and 'image_picker'.

Bubu added a commit to Bubu/plugins that referenced this issue Oct 23, 2020
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Nov 25, 2020
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Jan 3, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Feb 24, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
@victor-semenovich
Copy link

Adding the <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> permission leads to the warning message:

A <queries> declaration should generally be used instead of QUERY_ALL_PACKAGES; see https://g.co/dev/packagevisibility for details

A better solution is to add <queries> to the manifest file: https://stackoverflow.com/a/63246789/3129257

@k-zen
Copy link

k-zen commented Apr 8, 2021

This problem still occurs with target and compile SDK 30 and image_picker=0.7.4.

Adding this: <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> did not solved the problem. Tested on Android 10 (API 29).

[✓] Flutter (Channel stable, 2.0.4, on macOS 11.1 20C69 darwin-x64, locale en-CA)
    • Flutter version 2.0.4 at /Users/akc/Applications/flutter
    • Framework revision b1395592de (7 days ago), 2021-04-01 14:25:01 -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/akc/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/akc/Library/Android/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 at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 55.0.4
    • Dart plugin version 203.7759

[✓] Connected device (2 available)
    • Nokia 3 1 Plus (mobile) • ROOGAJG930901259 • android-arm64  • Android 10 (API 29)
    • Chrome (web)            • chrome           • web-javascript • Google Chrome 89.0.4389.114

• No issues found!

@omidraha
Copy link

omidraha commented Apr 17, 2021

Same issue here.

Info:

targetSdkVersion 30
compileSdkVersion 30
image_picker: ^0.7.4
Pixel 2 API 30 Android 11
$ flutter doctor --verbose
[✓] Flutter (Channel stable, 2.0.4, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.4 at /**/sdk/flutter
    • Framework revision b1395592de (2 weeks ago), 2021-04-01 14:25:01 -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at **/sdk/android/
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = **/sdk/android/
    • Java binary at: **/ide/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio
    • Android Studio at **/ide/android-studio/
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = **/ide/android-studio/
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
    • Linux (desktop)         • linux         • linux-x64   • Linux

! Doctor found issues in 1 categor

Related SO.

Update (Fixed by):

    <queries>
        <intent>
            <action android:name="android.media.action.IMAGE_CAPTURE" />
        </intent>
    </queries>

Bubu added a commit to Bubu/plugins that referenced this issue Apr 26, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue May 19, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Jun 24, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Jun 25, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Jul 5, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Jul 8, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Bubu added a commit to Bubu/plugins that referenced this issue Aug 2, 2021
resolveActivity(intent) might return false on android 11+_even though startActivity(intent) would succeed.
Instead of introducing a <queries> entry we can just try to start the
activity and catch the exception if that doesn't work.

Properly fixes flutter/flutter#62669.

Ref: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
@github-actions
Copy link

github-actions bot commented Aug 2, 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 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants