apache / cordova-plugin-camera

Apache Cordova Plugin camera
https://cordova.apache.org/
Apache License 2.0
964 stars 1.54k forks source link

Cannot open camera only on Google Pixel 3 #763

Open WuglyakBolgoink opened 2 years ago

WuglyakBolgoink commented 2 years ago

Bug Report

Problem

Cannot use camera app after migration on cordova-android@latest and cordova-plugin-camera@latest versions on GP-3.

Tested on

All this devices can open camera app without problem.

target SDK 30

Related to #734, #673

I don't have any access to the client logs to see what was happens. Any idea?

Do we need to add this permission? https://developer.android.com/reference/android/Manifest.permission#CAMERA

Checklist

breautek commented 2 years ago

Cannot really speak on the root issue but

Do we need to add this permission? https://developer.android.com/reference/android/Manifest.permission#CAMERA

This permission is only used for apps that uses the Camera APIs directly. This plugin does not use the Camera APIs. Instead it uses what Android calls Intents, which is to delegate the responsibility of taking an image using the camera by launching another app which does have the Camera permissions already to handle the camera operations. This is the recommended approach to use by Google and covers the needs of most apps.

There is one caveat however, if the application declares that the app uses the Camera permission, then you must have the Camera permission to use Intents. This is a case already handled via:

https://github.com/apache/cordova-plugin-camera/blob/0fba37cac3d2053d4c5f8acbb2cf0c5dbd0903be/src/android/CameraLauncher.java#L125

and

https://github.com/apache/cordova-plugin-camera/blob/0fba37cac3d2053d4c5f8acbb2cf0c5dbd0903be/src/android/CameraLauncher.java#L252-L284

WuglyakBolgoink commented 2 years ago

@breautek manual adding permission.CAMERA fix the problem on GP3!

beard7 commented 2 years ago

@WuglyakBolgoink How/where are you adding that? My AndroidManifest.xml already includes <uses-permission android:name="android.permission.CAMERA" />, but I've still got this issue on my GP3.

WuglyakBolgoink commented 2 years ago

Hallo @beard7

@WuglyakBolgoink How/where are you adding that? My AndroidManifest.xml already includes <uses-permission android:name="android.permission.CAMERA" />, but I've still got this issue on my GP3.

  1. install

    "cordova-custom-config": "5.1.0"

  2. check your config
  3. add custom config for CAMERA permission, because original cordova "edit-config" remove the first permission from manifest file!!!
  4. remove your platform folder
  5. generate platform folder again

<widget ...>
    ...
    <preference name="cordova-custom-config-autorestore" value="false" />
    <preference name="cordova-custom-config-stoponerror" value="true" />

    ...

    <platform name="android">
        <preference name="AndroidLaunchMode" value="singleTask" />

        <preference name="android-minSdkVersion" value="22" />
        <preference name="android-maxSdkVersion" value="31" />
        <preference name="android-targetSdkVersion" value="30" />

        <preference name="AndroidXEnabled" value="true" />

        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:name='MainActivity']">
            <activity xmlns:tools="http://schemas.android.com/tools" />
        </edit-config>

        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:name='MainActivity']">
            <activity android:requestLegacyExternalStorage="true" />
        </edit-config>

        <custom-config-file parent="./" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.CAMERA" />
        </custom-config-file>
    </platform>

    ...

</widget>

After that we can use camera on GP3 again...