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

[image_picker] canTakePhotos returns false when targeting API 30 #85599

Closed
kinex opened this issue Jun 30, 2021 · 7 comments · Fixed by flutter/plugins#3194
Closed

[image_picker] canTakePhotos returns false when targeting API 30 #85599

kinex opened this issue Jun 30, 2021 · 7 comments · Fixed by flutter/plugins#3194
Labels
found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: image_picker The Image Picker plugin. P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically

Comments

@kinex
Copy link

kinex commented Jun 30, 2021

It seems this check in ImagePickerDelegate.java does not work in Android 11:

private void launchTakeImageWithCameraIntent() {
.
.
.
    boolean canTakePhotos = intentResolver.resolveActivity(intent);

    if (!canTakePhotos) {
      finishWithError("no_available_camera", "No cameras available for taking pictures.");
      return;
    }

I have tested this in an emulator (API 30) and it throws the error "no_available_camera". If I comment out that code, I can take a photo with the emulator normally. Also one user has already reported me an issue he cannot take photos in my app with his Pixel 3 / Android 11 (my app targets API 30).

I think the issue is related to this:
https://stackoverflow.com/questions/62535856/intent-resolveactivity-returns-null-in-api-30

So the issue is here:

        new IntentResolver() {
          @Override
          public boolean resolveActivity(Intent intent) {
            // this check does not work in API 30
            return intent.resolveActivity(activity.getPackageManager()) != null;
          }
        },

image_picker: ^0.8.1+2

@kinex
Copy link
Author

kinex commented Jun 30, 2021

I fixed this by updating manifest with these:

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />

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

If build fails with those changes, you need to update gradle:

        classpath 'com.android.tools.build:gradle:4.0.1'

        distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

Optional fix would be to update plugin code as follows (updating manifest not needed in this case):

  1. Remove the code checking if photos can be taken
  2. Start activity like this:
try {
    activity.startActivityForResult(intent, REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA);
} catch (ActivityNotFoundException e) {
    finishWithError("no_available_camera", "No cameras available for taking pictures.");
    return;
}

Personally I would prefer fixing plugin code (for easier installation steps and fixing current installations "automatically"), but if you are planning to add a public API for only checking if a camera is available, then updating the manifest is required.

@TahaTesser TahaTesser added the in triage Presently being triaged by the triage team label Jun 30, 2021
@TahaTesser
Copy link
Member

Hi @kinex
This is only caused by targeting API 30 as the package is not targeted for this API. I can reproduce it on an emulator then I tried a physical Android 11 device., taking a pic with a camera works fine

logs
[  +82 ms] Syncing files to device SM M025F...
[   +2 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[   +2 ms] <- recompile package:stable_flutter/main.dart 70959f8b-350f-4e3e-9dfe-ba8bc467cd5a
[        ] <- 70959f8b-350f-4e3e-9dfe-ba8bc467cd5a
[ +101 ms] Updating files.
[        ] DevFS: Sync finished
[   +1 ms] Syncing files to device SM M025F... (completed in 107ms)
[   +1 ms] Synced 0.0MB.
[   +1 ms] <- accept
[  +15 ms] Connected to _flutterView/0xccdbb410.
[   +2 ms] Flutter run key commands.
[   +1 ms] r Hot reload. 🔥🔥🔥
[   +1 ms] R Hot restart.
[        ] h Repeat this help message.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[        ] q Quit (terminate the application on the device).
[        ] 💪 Running with sound null safety 💪
[        ] An Observatory debugger and profiler on SM M025F is available at: http://127.0.0.1:51398/qq9igZOtSKs=/
[ +713 ms] The Flutter DevTools debugger and profiler on SM M025F is available at:
                    http://127.0.0.1:9101?uri=http%3A%2F%2F127.0.0.1%3A51398%2Fqq9igZOtSKs%3D%2F
[+3083 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3937359264]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3937359264]
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3360420064]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3360420064]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3360420000]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3360420000]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3426000032]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3426000032]
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)0 dur=18 res=0x1 s={true 3361094656} ch=false fn=2
[+52191 ms] D/InputMethodManager(20708): prepareNavigationBarInfo() DecorView@8c5d220[MainActivity]
[   +1 ms] D/InputMethodManager(20708): getNavigationBarColor() -16711423
[        ] V/InputMethodManager(20708): Starting input: tba=com.example.stable_flutter ic=null mNaviBarColor -16711423
mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
[        ] D/InputMethodManager(20708): startInputInner - Id : 0
[        ] I/InputMethodManager(20708): startInputInner - mService.startInputOrWindowGainedFocus
[        ] D/InputTransport(20708): Input channel constructed: 'ClientS', fd=96
[        ] D/InputTransport(20708): Input channel destroyed: 'ClientS', fd=98
[ +357 ms] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(true) old=false
[   +1 ms] I/SurfaceView(20708): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574} of ViewRootImpl@8715daa[MainActivity]
[        ] I/SurfaceView(20708): surfaceDestroyed callback.size 1 #1
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574}
[        ] I/SurfaceView(20708): remove() io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........
0,0-720,1574} Surface(name=SurfaceView -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@647c538@0)/@0x1cd924e
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937359456]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937359456]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937360896]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937360896]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937361472]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937361472]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3939407296]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3939407296]
[  +18 ms] I/SurfaceView(20708): onWindowVisibilityChanged(8) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[  +18 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x1e59bd6 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1810
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3491487712]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3491487712]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3360420320]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3360420320]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937359264]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937359264]
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)8 dur=22 res=0x5 s={false 0} ch=false fn=-1
[ +140 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_WINDOW_FOCUS_CHANGED 0 1
[ +181 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3491486912]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3491486912]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3905393312]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3905393312]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937361472]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937361472]
[+55050 ms] I/SurfaceView(20708): onWindowVisibilityChanged(4) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[  +15 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x1e59bd6 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1810
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3360420128]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3360420128]
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)4 dur=12 res=0x1 s={false 0} ch=false fn=-1
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(false) old=true
[   +6 ms] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(false) old=false
[   +2 ms] I/SurfaceView(20708): onWindowVisibilityChanged(0) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[  +15 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3491486912]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3491486912]
[   +2 ms] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)0 dur=13 res=0x7 s={true 3115828224} ch=true fn=-1
[        ] I/SurfaceView(20708): windowStopped(false) true io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574} of ViewRootImpl@8715daa[MainActivity]
[   +2 ms] I/SurfaceView(20708): surfaceCreated 1 #1 io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E......
........ 0,0-720,1574}
[   +1 ms] I/SurfaceView(20708): surfaceChanged (720,1574) 1 #1 io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574}
[   +7 ms] I/ViewRootImpl@8715daa[MainActivity](20708): updateBoundsLayer: shouldReparent = true t =
android.view.SurfaceControl$Transaction@44a7e2d sc = Surface(name=Bounds for -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@1)/@0x9f79f62 frame = 1
[   +2 ms] I/SurfaceView(20708): applySurfaceTransforms: t = android.view.SurfaceControl$Transaction@63df949
surfaceControl = Surface(name=SurfaceView -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@647c538@1)/@0x8cae8f3 frame = 1
[  +72 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3937359328]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937359328]
[   +2 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_RESIZED_REPORT: frame=(0,0,720,1600) ci=(0,45,0,26)
vi=(0,45,0,26) or=1
[  +25 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3937361344]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3937361344]
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3425999872]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3425999872]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3360420160]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3360420160]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3941816640]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3941816640]
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)0 dur=14 res=0x1 s={true 3115828224} ch=false fn=2
[   +6 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_WINDOW_FOCUS_CHANGED 1 1
[   +1 ms] D/InputMethodManager(20708): prepareNavigationBarInfo() DecorView@8c5d220[MainActivity]
[        ] D/InputMethodManager(20708): getNavigationBarColor() -16711423
[   +1 ms] D/InputMethodManager(20708): prepareNavigationBarInfo() DecorView@8c5d220[MainActivity]
[        ] D/InputMethodManager(20708): getNavigationBarColor() -16711423
[        ] V/InputMethodManager(20708): Starting input: tba=com.example.stable_flutter ic=null mNaviBarColor -16711423
mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
[        ] D/InputMethodManager(20708): startInputInner - Id : 0
[        ] I/InputMethodManager(20708): startInputInner - mService.startInputOrWindowGainedFocus
[        ] D/InputTransport(20708): Input channel constructed: 'ClientS', fd=102
[        ] D/InputTransport(20708): Input channel destroyed: 'ClientS', fd=96
[ +949 ms] I/ViewRootImpl@8715daa[MainActivity](20708): ViewPostIme pointer 0
[  +30 ms] I/ViewRootImpl@8715daa[MainActivity](20708): ViewPostIme pointer 1
[+2937 ms] I/ViewRootImpl@8715daa[MainActivity](20708): ViewPostIme pointer 0
[  +22 ms] I/ViewRootImpl@8715daa[MainActivity](20708): ViewPostIme pointer 1
[ +126 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_WINDOW_FOCUS_CHANGED 0 1
[ +182 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3937361344]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3937361344]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3116017376]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3116017376]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3436964096]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3436964096]
[ +231 ms] D/InputTransport(20708): Input channel destroyed: 'ClientS', fd=102
[  +19 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3117318080]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3117318080]
[ +179 ms] I/SurfaceView(20708): onWindowVisibilityChanged(8) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[   +1 ms] I/SurfaceView(20708): surfaceDestroyed callback.size 1 #2
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574}
[  +22 ms] I/SurfaceView(20708): remove() from RT android.view.SurfaceView$2@e651d5b Surface(name=SurfaceView -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@647c538@1)/@0x8cae8f3
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3491487040]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3491487040]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3436964032]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3436964032]
[   +6 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3937360896]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3937360896]
[        ] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x1e59bd6 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1810
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3491487008]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3491487008]
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)8 dur=14 res=0x5 s={false 0} ch=true fn=4
[        ] I/SurfaceView(20708): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574} of ViewRootImpl@8715daa[MainActivity]
[   +3 ms] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(true) old=false
[+4673 ms] I/SurfaceView(20708): onWindowVisibilityChanged(4) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[  +30 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x1e59bd6 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1810
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)4 dur=20 res=0x1 s={false 0} ch=false fn=-1
[   +1 ms] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(false) old=true
[   +8 ms] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(false) old=false
[   +7 ms] I/SurfaceView(20708): onWindowVisibilityChanged(0) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[  +22 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +5 ms] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)0 dur=22 res=0x7 s={true 3115828224} ch=true fn=-1
[   +1 ms] D/MediaScannerConnection(20708): Scanned
/data/user/0/com.example.stable_flutter/cache/44569a5b-ab0a-42ab-a3b0-e85eb183b43a6292253585777522939.jpg to null
[   +8 ms] I/SurfaceView(20708): windowStopped(false) true io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574} of ViewRootImpl@8715daa[MainActivity]
[   +1 ms] I/SurfaceView(20708): surfaceCreated 1 #1 io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E......
........ 0,0-720,1574}
[   +1 ms] I/SurfaceView(20708): surfaceChanged (720,1574) 1 #1 io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574}
[   +3 ms] I/ViewRootImpl@8715daa[MainActivity](20708): updateBoundsLayer: shouldReparent = true t =
android.view.SurfaceControl$Transaction@44a7e2d sc = Surface(name=Bounds for -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@2)/@0x7138010 frame = 1
[  +10 ms] I/SurfaceView(20708): applySurfaceTransforms: t = android.view.SurfaceControl$Transaction@63df949
surfaceControl = Surface(name=SurfaceView -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@647c538@2)/@0xb29709 frame = 1
[  +28 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_RESIZED_REPORT: frame=(0,0,720,1600) ci=(0,45,0,26)
vi=(0,45,0,26) or=1
[  +17 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_WINDOW_FOCUS_CHANGED 1 1
[   +1 ms] D/InputMethodManager(20708): prepareNavigationBarInfo() DecorView@8c5d220[MainActivity]
[        ] D/InputMethodManager(20708): getNavigationBarColor() -16711423
[   +1 ms] D/InputMethodManager(20708): prepareNavigationBarInfo() DecorView@8c5d220[MainActivity]
[   +1 ms] D/InputMethodManager(20708): getNavigationBarColor() -16711423
[   +1 ms] V/InputMethodManager(20708): Starting input: tba=com.example.stable_flutter ic=null mNaviBarColor -16711423
mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
[        ] D/InputMethodManager(20708): startInputInner - Id : 0
[        ] I/InputMethodManager(20708): startInputInner - mService.startInputOrWindowGainedFocus
[   +3 ms] D/InputTransport(20708): Input channel constructed: 'ClientS', fd=103
[  +29 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3941736032]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3941736032]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3360420192]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3360420192]
[ +242 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3899094240]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3899094240]
[+59634 ms] D/InputMethodManager(20708): prepareNavigationBarInfo() DecorView@8c5d220[MainActivity]
[   +1 ms] D/InputMethodManager(20708): getNavigationBarColor() -16711423
[        ] V/InputMethodManager(20708): Starting input: tba=com.example.stable_flutter ic=null mNaviBarColor -16711423
mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
[        ] D/InputMethodManager(20708): startInputInner - Id : 0
[        ] I/InputMethodManager(20708): startInputInner - mService.startInputOrWindowGainedFocus
[        ] D/InputTransport(20708): Input channel constructed: 'ClientS', fd=107
[        ] D/InputTransport(20708): Input channel destroyed: 'ClientS', fd=103
[ +368 ms] I/ViewRootImpl@8715daa[MainActivity](20708): stopped(true) old=false
[   +2 ms] I/SurfaceView(20708): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{647c538
V.E...... ........ 0,0-720,1574} of ViewRootImpl@8715daa[MainActivity]
[   +2 ms] I/SurfaceView(20708): surfaceDestroyed callback.size 1 #1
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574}
[   +9 ms] I/SurfaceView(20708): remove() io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........
0,0-720,1574} Surface(name=SurfaceView -
com.example.stable_flutter/com.example.stable_flutter.MainActivity@647c538@2)/@0xb29709
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3937360800]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937360800]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937361440]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937361440]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3899094144]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3899094144]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3875193568]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3875193568]
[   +1 ms] I/SurfaceView(20708): onWindowVisibilityChanged(8) false
io.flutter.embedding.android.FlutterSurfaceView{647c538 V.E...... ........ 0,0-720,1574} of
ViewRootImpl@8715daa[MainActivity]
[  +28 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x1e59bd6 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1810
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): assignNativeObject: nativeObject = 0 Surface(name=null)/@0x8efb877 /
android.view.SurfaceControl.readFromParcel:1115 android.view.IWindowSession$Stub$Proxy.relayout:1820
android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360
android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971
android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809
android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3939406944]
[   +1 ms] I/SurfaceControl(20708): nativeRelease nativeObject e[3939406944]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3939406880]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3939406880]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3491704832]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3491704832]
[        ] I/ViewRootImpl@8715daa[MainActivity](20708): Relayout returned: old=(0,0,720,1600) new=(0,0,720,1600)
req=(720,1600)8 dur=27 res=0x5 s={false 0} ch=false fn=-1
[ +128 ms] I/ViewRootImpl@8715daa[MainActivity](20708): MSG_WINDOW_FOCUS_CHANGED 0 1
[ +194 ms] I/SurfaceControl(20708): nativeRelease nativeObject s[3902507744]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3902507744]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3899093536]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3899093536]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject s[3937360800]
[        ] I/SurfaceControl(20708): nativeRelease nativeObject e[3937360800]
flutter doctor -v
[✓] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19043.1081], locale en-US)
    • Flutter version 2.2.2 at C:\Users\Taha\Code\flutter_stable
    • Framework revision d79295af24 (3 weeks ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[✓] 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_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java.exe
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.2)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.10.31410.357
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

[✓] VS Code (version 1.57.1)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.23.0

[✓] Connected device (5 available)
    • SM M025F (mobile)       • R9ZR205XX0A   • android-arm    • Android 11 (API 30)
    • sdk gphone x86 (mobile) • emulator-5556 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19043.1081]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 91.0.4472.114
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 91.0.864.59

! Doctor found issues in 1 category.

If you've Android 11 device, can you please provide logs running the official example
Thnk you

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 30, 2021
@kinex
Copy link
Author

kinex commented Jun 30, 2021

Sorry I don't have any Android 11 devices.

What do you mean by the "package is not targeted for this API"? targetSdkVersion is defined for an app (in AndroidManifest.xml) and not for plugins.

If you try with the official example, please set targetSdkVersion to 30 (and compileSdkVersion to 30, but it is not important to reproduce the issue). Those are also the defaults if you create a new Flutter app or a package (Flutter 2.2.2). I believe you need Android 11 device/emulator + targetSdkVersion 30 to reproduce the issue.

@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 Jun 30, 2021
@TahaTesser
Copy link
Member

Hi @kinex
image_picker still targets API 28, if it targets higher API, it needs to accommodate API changes introduced in higher API.

I have got a couple of Android 11 devices and emulator, compared the result by setting a breakpoint to boolean canTakePhotos = intentResolver.resolveActivity(intent);, it does return false on both device and simulator when targetting API 30

After chaanging the app target API to 30z
It seems on the physical device, the breakpoint is reached, returns true

Used the following minimal code sample

minimal code sample
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';
import 'dart:io';

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Image Picker Demo',
      home: MyHomePage(title: 'Image Picker Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, this.title}) : super(key: key);

  final String? title;

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

class _MyHomePageState extends State<MyHomePage> {
  List<PickedFile>? _imageFileList;

  set _imageFile(PickedFile? value) {
    _imageFileList = value == null ? null : [value];
  }

  dynamic _pickImageError;
  bool isVideo = false;

  VideoPlayerController? _controller;
  VideoPlayerController? _toBeDisposed;
  String? _retrieveDataError;

  final ImagePicker _picker = ImagePicker();
  final TextEditingController maxWidthController = TextEditingController();
  final TextEditingController maxHeightController = TextEditingController();
  final TextEditingController qualityController = TextEditingController();

  Future<void> _playVideo(PickedFile? file) async {
    if (file != null && mounted) {
      await _disposeVideoController();
      late VideoPlayerController controller;
      if (kIsWeb) {
        controller = VideoPlayerController.network(file.path);
      } else {
        controller = VideoPlayerController.file(File(file.path));
      }
      _controller = controller;
      // In web, most browsers won't honor a programmatic call to .play
      // if the video has a sound track (and is not muted).
      // Mute the video so it auto-plays in web!
      // This is not needed if the call to .play is the result of user
      // interaction (clicking on a "play" button, for example).
      final double volume = kIsWeb ? 0.0 : 1.0;
      await controller.setVolume(volume);
      await controller.initialize();
      await controller.setLooping(true);
      await controller.play();
      setState(() {});
    }
  }

  void _onImageButtonPressed(ImageSource source,
      {BuildContext? context, bool isMultiImage = false}) async {
    if (_controller != null) {
      await _controller!.setVolume(0.0);
    }
    if (isVideo) {
      final PickedFile? file = await _picker.getVideo(
          source: source, maxDuration: const Duration(seconds: 10));
      await _playVideo(file);
    } else if (isMultiImage) {
      await _displayPickImageDialog(context!,
          (double? maxWidth, double? maxHeight, int? quality) async {
        try {
          final pickedFileList = await _picker.getMultiImage(
            maxWidth: maxWidth,
            maxHeight: maxHeight,
            imageQuality: quality,
          );
          setState(() {
            _imageFileList = pickedFileList;
          });
        } catch (e) {
          setState(() {
            _pickImageError = e;
          });
        }
      });
    } else {
      await _displayPickImageDialog(context!,
          (double? maxWidth, double? maxHeight, int? quality) async {
        try {
          final pickedFile = await _picker.getImage(
            source: source,
            maxWidth: maxWidth,
            maxHeight: maxHeight,
            imageQuality: quality,
          );
          setState(() {
            _imageFile = pickedFile;
          });
        } catch (e) {
          setState(() {
            _pickImageError = e;
          });
        }
      });
    }
  }

  @override
  void deactivate() {
    if (_controller != null) {
      _controller!.setVolume(0.0);
      _controller!.pause();
    }
    super.deactivate();
  }

  @override
  void dispose() {
    _disposeVideoController();
    maxWidthController.dispose();
    maxHeightController.dispose();
    qualityController.dispose();
    super.dispose();
  }

  Future<void> _disposeVideoController() async {
    if (_toBeDisposed != null) {
      await _toBeDisposed!.dispose();
    }
    _toBeDisposed = _controller;
    _controller = null;
  }

  Widget _previewVideo() {
    final Text? retrieveError = _getRetrieveErrorWidget();
    if (retrieveError != null) {
      return retrieveError;
    }
    if (_controller == null) {
      return const Text(
        'You have not yet picked a video',
        textAlign: TextAlign.center,
      );
    }
    return Padding(
      padding: const EdgeInsets.all(10.0),
      child: AspectRatioVideo(_controller),
    );
  }

  Widget _previewImages() {
    final Text? retrieveError = _getRetrieveErrorWidget();
    if (retrieveError != null) {
      return retrieveError;
    }
    if (_imageFileList != null) {
      return Semantics(
          child: ListView.builder(
            key: UniqueKey(),
            itemBuilder: (context, index) {
              // Why network for web?
              // See https://pub.dev/packages/image_picker#getting-ready-for-the-web-platform
              return Semantics(
                label: 'image_picker_example_picked_image',
                child: kIsWeb
                    ? Image.network(_imageFileList![index].path)
                    : Image.file(File(_imageFileList![index].path)),
              );
            },
            itemCount: _imageFileList!.length,
          ),
          label: 'image_picker_example_picked_images');
    } else if (_pickImageError != null) {
      return Text(
        'Pick image error: $_pickImageError',
        textAlign: TextAlign.center,
      );
    } else {
      return const Text(
        'You have not yet picked an image.',
        textAlign: TextAlign.center,
      );
    }
  }

  Widget _handlePreview() {
    if (isVideo) {
      return _previewVideo();
    } else {
      return _previewImages();
    }
  }

  Future<void> retrieveLostData() async {
    final LostData response = await _picker.getLostData();
    if (response.isEmpty) {
      return;
    }
    if (response.file != null) {
      if (response.type == RetrieveType.video) {
        isVideo = true;
        await _playVideo(response.file);
      } else {
        isVideo = false;
        setState(() {
          _imageFile = response.file;
        });
      }
    } else {
      _retrieveDataError = response.exception!.code;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title!),
      ),
      body: Center(
        child: !kIsWeb && defaultTargetPlatform == TargetPlatform.android
            ? FutureBuilder<void>(
                future: retrieveLostData(),
                builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
                  switch (snapshot.connectionState) {
                    case ConnectionState.none:
                    case ConnectionState.waiting:
                      return const Text(
                        'You have not yet picked an image.',
                        textAlign: TextAlign.center,
                      );
                    case ConnectionState.done:
                      return _handlePreview();
                    default:
                      if (snapshot.hasError) {
                        return Text(
                          'Pick image/video error: ${snapshot.error}}',
                          textAlign: TextAlign.center,
                        );
                      } else {
                        return const Text(
                          'You have not yet picked an image.',
                          textAlign: TextAlign.center,
                        );
                      }
                  }
                },
              )
            : _handlePreview(),
      ),
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          Semantics(
            label: 'image_picker_example_from_gallery',
            child: FloatingActionButton(
              onPressed: () {
                isVideo = false;
                _onImageButtonPressed(ImageSource.gallery, context: context);
              },
              heroTag: 'image0',
              tooltip: 'Pick Image from gallery',
              child: const Icon(Icons.photo),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 16.0),
            child: FloatingActionButton(
              onPressed: () {
                isVideo = false;
                _onImageButtonPressed(
                  ImageSource.gallery,
                  context: context,
                  isMultiImage: true,
                );
              },
              heroTag: 'image1',
              tooltip: 'Pick Multiple Image from gallery',
              child: const Icon(Icons.photo_library),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 16.0),
            child: FloatingActionButton(
              onPressed: () {
                isVideo = false;
                _onImageButtonPressed(ImageSource.camera, context: context);
              },
              heroTag: 'image2',
              tooltip: 'Take a Photo',
              child: const Icon(Icons.camera_alt),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 16.0),
            child: FloatingActionButton(
              backgroundColor: Colors.red,
              onPressed: () {
                isVideo = true;
                _onImageButtonPressed(ImageSource.gallery);
              },
              heroTag: 'video0',
              tooltip: 'Pick Video from gallery',
              child: const Icon(Icons.video_library),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 16.0),
            child: FloatingActionButton(
              backgroundColor: Colors.red,
              onPressed: () {
                isVideo = true;
                _onImageButtonPressed(ImageSource.camera);
              },
              heroTag: 'video1',
              tooltip: 'Take a Video',
              child: const Icon(Icons.videocam),
            ),
          ),
        ],
      ),
    );
  }

  Text? _getRetrieveErrorWidget() {
    if (_retrieveDataError != null) {
      final Text result = Text(_retrieveDataError!);
      _retrieveDataError = null;
      return result;
    }
    return null;
  }

  Future<void> _displayPickImageDialog(
      BuildContext context, OnPickImageCallback onPick) async {
    return showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('Add optional parameters'),
            content: Column(
              children: <Widget>[
                TextField(
                  controller: maxWidthController,
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                  decoration:
                      InputDecoration(hintText: "Enter maxWidth if desired"),
                ),
                TextField(
                  controller: maxHeightController,
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                  decoration:
                      InputDecoration(hintText: "Enter maxHeight if desired"),
                ),
                TextField(
                  controller: qualityController,
                  keyboardType: TextInputType.number,
                  decoration:
                      InputDecoration(hintText: "Enter quality if desired"),
                ),
              ],
            ),
            actions: <Widget>[
              TextButton(
                child: const Text('CANCEL'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              TextButton(
                  child: const Text('PICK'),
                  onPressed: () {
                    double? width = maxWidthController.text.isNotEmpty
                        ? double.parse(maxWidthController.text)
                        : null;
                    double? height = maxHeightController.text.isNotEmpty
                        ? double.parse(maxHeightController.text)
                        : null;
                    int? quality = qualityController.text.isNotEmpty
                        ? int.parse(qualityController.text)
                        : null;
                    onPick(width, height, quality);
                    Navigator.of(context).pop();
                  }),
            ],
          );
        });
  }
}

typedef void OnPickImageCallback(
    double? maxWidth, double? maxHeight, int? quality);

class AspectRatioVideo extends StatefulWidget {
  AspectRatioVideo(this.controller);

  final VideoPlayerController? controller;

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

class AspectRatioVideoState extends State<AspectRatioVideo> {
  VideoPlayerController? get controller => widget.controller;
  bool initialized = false;

  void _onVideoControllerUpdate() {
    if (!mounted) {
      return;
    }
    if (initialized != controller!.value.isInitialized) {
      initialized = controller!.value.isInitialized;
      setState(() {});
    }
  }

  @override
  void initState() {
    super.initState();
    controller!.addListener(_onVideoControllerUpdate);
  }

  @override
  void dispose() {
    controller!.removeListener(_onVideoControllerUpdate);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    if (initialized) {
      return Center(
        child: AspectRatio(
          aspectRatio: controller!.value.aspectRatio,
          child: VideoPlayer(controller!),
        ),
      );
    } else {
      return Container();
    }
  }
}
stable master

Check flutter doctor -v outputs for each channel below

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1081], locale en-US)
    • Flutter version 2.2.3 at C:\Users\Taha\Code\flutter_stable
    • Framework revision f4abaa0735 (15 hours ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] 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_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java.exe
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.2)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.10.31410.357
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

[✓] VS Code (version 1.57.1)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.23.0

[✓] Connected device (5 available)
    • SM M025F (mobile)       • R9ZR205XX0A   • android-arm    • Android 11 (API 30)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19043.1081]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 91.0.4472.124
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 91.0.864.59

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 2.3.0-17.0.pre.629, on Microsoft Windows [Version 10.0.19043.1081], locale en-US)
    • Flutter version 2.3.0-17.0.pre.629 at C:\Users\Taha\Code\flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6c92cb5169 (4 hours ago), 2021-07-02 02:51:02 -0400
    • Engine revision e8785b6ac3
    • Dart version 2.14.0 (build 2.14.0-269.0.dev)

[✓] 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_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.2)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.10.31410.357
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 4.2.0)
    • Android Studio at C:\Users\Taha\Code\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
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

[✓] VS Code (version 1.57.1)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.23.0

[✓] Connected device (6 available)
    • SM M025F (mobile)       • R9ZR205XX0A   • android-arm     • Android 11 (API 30)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86     • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64     • Microsoft Windows [Version 10.0.19043.1081]
    • Windows (UWP) (desktop) • winuwp        • windows-uwp-x64 •
    • Chrome (web)            • chrome        • web-javascript  • Google Chrome 91.0.4472.124
    • Edge (web)              • edge          • web-javascript  • Microsoft Edge 91.0.864.59

• No issues found!

✅ : No Issue ❌: Issue reproduced

@TahaTesser TahaTesser changed the title [image_picker] Taking a photo with a camera does not work in Android 11 [image_picker] canTakePhotos returns false when targeting API 30 Jul 2, 2021
@TahaTesser TahaTesser added found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: first party p: image_picker The Image Picker plugin. platform-android Android applications specifically and removed in triage Presently being triaged by the triage team labels Jul 2, 2021
@stuartmorgan
Copy link
Contributor

I believe this is the issue fixed by flutter/plugins#3194

@kinex
Copy link
Author

kinex commented Jul 8, 2021

Yes it is the same issue.

@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label Jul 15, 2021
@github-actions
Copy link

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 23, 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
found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: image_picker The Image Picker plugin. P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants