ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
519 stars 585 forks source link

Camera opens after second attempt on Android #2210

Open daniil777555 opened 5 days ago

daniil777555 commented 5 days ago

On newer versions of android camera opens after 2 attempts. I call Camera.getPhoto with option saveToGallery set to true. The the system bottom sheet appears and I choose Take a photo, then the sheet disappears and nothing, I have to click the button again to call Camera.getPhoto and again choose Take a photo. But, if I set saveToGallery to false, everything works as expected. Also worth mentioning that after these manipulations camera opens from the first attempt until I restart the app. I've tried disabling camera permissions and plugin doesn't ask any, I've tried manually request permissions but nothing pops up, I've tried manually enable permissions in settings and bug still presents. And one more thing, I've put console.log after await Camera.getPhoto and nothing appears in console on a first attempt when Camera didn't show off but on second my console.log has been fired.

I've tried to update these things as Android studio suggests despite Capacitor documentation says these versions should be set but it didn't help. classpath 'com.google.gms:google-services:4.4.0' classpath 'com.android.tools.build:gradle:8.2.1' distributionUrl=https://services.gradle.org/distributions/gradle-8.2.1-all.zip

Capacitor dependencies "@capacitor/android": "^6.1.2", "@capacitor/app": "^6.0.1", "@capacitor/camera": "^6.0.2",

Ionitron commented 4 days ago

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks! Ionitron 💙

daniil777555 commented 4 days ago

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks! Ionitron 💙

Repository with reproduction https://github.com/daniil777555/capacitor-camera-reproduction

Camera won't open on a first attempt to take a photo. It has been tested on Android APIs 33,34,35 For old versions of Android it works fine

This bug is noticed when saveToGallery is set to true but if it's false then it works

Also additional bug, that Camera.requestPermissions() doesn't request permissions on Android

More detailed explanation, after initial loading or restarting the app, clicking button you see a prompt to choose whether to take a photo or choose from gallery, but after choosing to take a photo, camera won't open you must click the button again and choose Take a photo again, then camera will open. After you did it once, camera will open on a first attempt until you restart the app.

JazzShapka commented 3 days ago

I have exactly the same problem on new versions of Android. There is also a problem with the permission request, it does not appear. This is critical for my application... Let me know if there is any solution.