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

Error Code 20 on Android #826

Closed
3 tasks done
jkenjarCR opened this issue Feb 28, 2023 · 29 comments
Closed
3 tasks done

Error Code 20 on Android #826

jkenjarCR opened this issue Feb 28, 2023 · 29 comments

Comments

@jkenjarCR
Copy link

jkenjarCR commented Feb 28, 2023

Bug Report

Problem

What is expected to happen?

What does actually happen?

Screenshot_20230228-112443

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek
Copy link
Contributor

Please edit the post and provide the requested information in the form. Definitely include code snippets and version information.

@prabusharan
Copy link

prabusharan commented Apr 3, 2023

image

image

Good Morning @breautek,

The same issue occurs in android 11 "Camera issue:20" to unable open the camera. Below I include the AndroidManifest.xml file for your reference. can you please help me to resolve this issue

<?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareAccelerated="true" android:versionCode="50100" android:versionName="5.1" package="com.test.app" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:requestLegacyExternalStorage="true" android:supportsRtl="true" android:usesCleartextTraffic="true"> <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.App.SplashScreen" android:windowSoftInputMode="adjustResize"> <intent-filter android:label="@string/launcher_name"> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <provider android:authorities="${applicationId}.cordova.plugin.camera.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" /> </provider> <service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" /> <service android:exported="false" android:name="org.apache.cordova.firebase.FirebasePluginMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver" /> <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/accent" /> <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" /> <meta-data android:name="firebase_analytics_collection_enabled" android:value="true" /> <meta-data android:name="firebase_performance_collection_enabled" android:value="true" /> <meta-data android:name="firebase_crashlytics_collection_enabled" android:value="true" /> <meta-data android:name="firebase_messaging_auto_init_enabled" android:value="true" /> <service android:name="cordova.plugin.floatview.MyService" /> </application> <uses-permission android:name="android.hardware.location" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:maxSdkVersion="32" android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" /> <queries> <intent> <action android:name="android.media.action.IMAGE_CAPTURE" /> </intent> <intent> <action android:name="android.intent.action.GET_CONTENT" /> </intent> <intent> <action android:name="android.intent.action.PICK" /> </intent> <intent> <action android:name="com.android.camera.action.CROP" /> <data android:mimeType="image/*" android:scheme="content" /> </intent> </queries> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-feature android:name="android.hardware.location.gps" android:required="true" /> <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-feature android:name="android.hardware.telephony" android:required="false" /> </manifest>

@AndrWeisR
Copy link

AndrWeisR commented May 26, 2023

Same error here. Here's my code. I'm upgrading my Ionic app (where selecting a photo from the gallery previously worked) to support API 33, using Cordova 12.0.0. I upgraded the camera plugin to 6.0.0, but still get error 20. I'm getting this error on Android 13.

    const options: CameraOptions = {
      mediaType: this.camera.MediaType.PICTURE,
      correctOrientation: true,
      targetWidth: 1024,
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      destinationType: this.camera.DestinationType.FILE_URI
    };

    this.camera.getPicture(options).then((imageData) => {
        ....
    }, (err) => {
      console.log(err); <== This outputs "20".
    });

@levieu
Copy link

levieu commented Jun 13, 2023

To fix the problem you can use the following fork. The 'Error code 20' problem is due to the failure to request the READ_MEDIA_IMAGES permission; this permission was introduced by android starting from api level 33 link

@epetre
Copy link

epetre commented Jun 13, 2023

Thx.
I tried this your fork and it didn't work for me, the camera hangs too.
But from what I saw, the changes you have there are covered in this PR too aren't they?

@brunoalex
Copy link

same problem

@jimbergman
Copy link

jimbergman commented Jun 16, 2023

I'm experiencing the same issue.

Running cordova@12.0.0 (command line tools)
these settings don't work with the camera plugin:
<preference name="android-targetSdkVersion" value="33" />
<engine name="android" spec="12.0.0" />

it works fine rolling back to these settings:
<preference name="android-targetSdkVersion" value="32" />
<engine name="android" spec="11.0.0" />

changing the targetSdk to 32 without also setting android to 11 throws an error at build

the ticking clock here is Google's targetSdk 33 requirement starting on Aug 31, 2023
https://developer.android.com/google/play/requirements/target-sdk

EDIT: the fork by levieu above did not work for me

@cyril23
Copy link

cyril23 commented Jun 20, 2023

EDIT: the fork by levieu above did not work for me

same here for me. Testing on Android 13.0.0 on a OnePlus 9 Pro (edit: I've tested another Android 13 device, the Google Pixel 7):

I've tried the following repos and finally found a working one:

So I've solved the Issue for me by including
<plugin name="cordova-plugin-camera" spec="https://github.com/jalios/cordova-plugin-camera.git" />
instead of
<plugin name="cordova-plugin-camera" spec="6.0.0" />

@epetre
Copy link

epetre commented Jun 20, 2023

Thx @cyril23 🔥 🙌

It also works on my Samsung S20, with Cordova 12, Android 13 API 33.

@cyril23
Copy link

cyril23 commented Jun 20, 2023

Thx @cyril23 🔥 🙌

It also works on my Samsung S20, with Cordova 12, Android 13 API 33.

glad to hear, but the https://github.com/jalios/cordova-plugin-camera/ fork still has some problems on an old X10302 tablet running Android 7.0.0. On that Android 7 device it is not the error 20 though:
image

  • so on this Android 7 device I get an error Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=7790, uid=10046 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
  • In order to take pictures on the Android 7 within my app, I needed to manually set the storage permission within Settings -> Apps -> (my app) -> permissions.
  • The "camera" setting has been requested successfully by the plugin, but the "storage" permission apparently hasn't been requested correctly by the plugin, so I had to allow it myself manually. (This is probably caused because my app crashed when starting the camera for the first time and requesting permissions for the first time. During the crash apparently only the "camera" permission has been set successfully - and the "storage" permission not.)
  • On the Apache 6.0.0 Version the plugin requests two permissions, both camera and storage permissions, and therefore the Apache 6.0.0 works without a problem on this old Android 7.0.0 device. But the Apache 6.0.0 version of course has the error 20 problem on Android 13 phones, so there is that.
  • Anyhow: If the user is lucky and has already allowed the external storage successfully (e.g. via an old app using the Apache 6.0.0 version), and only gets an update of the app via Play Store, the camera can be used without a problem.

The same storage permission problem exists on Android 8.1.0 too, on an old Nexus 5X (LG H791).
In all cases, no error "20" anymore though.

edit: further information about the X10302 tablet running Android 7.0.0 and about my Nexus 5X (LG H791) running Android 8.1.0

@matheus-inacio
Copy link

I've created an app from zero and ran on an emulator with android 13, i was getting this error as well.

Oddly enough, if i keep pressing the camera button multiples times really fast, it eventually opens the camera app (?!?) 😕

@DaedalusDev
Copy link

DaedalusDev commented Jun 27, 2023

@cyril23 Here a fork inspired from the work of @jalios. Work perfectly on Android 13, 7 and 8 🎉

https://github.com/DaedalusDev/cordova-plugin-camera/

I've only change that rows to match original code :

-        boolean saveAlbumPermission;
-        if (this.saveToPhotoAlbum) {
-            saveAlbumPermission = hasPermissions(storagePermissions);
-        } else {
-            saveAlbumPermission = true;
-        }
+        boolean saveAlbumPermission = hasPermissions(storagePermissions);

I've also suggest that change in a sibling merge request (#814 https://github.com/apache/cordova-plugin-camera/pull/814/files#r1243650007)

Good luck !

@FrancescoPaiola
Copy link

FrancescoPaiola commented Jun 27, 2023

I'm using ionic 6 (capacitor 5).
As mentioned by @cyril23 the jalios fork worked for me (the fix is here).
To that follow these steps:

// uninstall cordova-plugin-camera
npm uninstall cordova-plugin-camera 
// install jalios fork
npm i https://github.com/jalios/cordova-plugin-camera.git
// if it's not already installed
npm install @awesome-cordova-plugins/camera 
ionic cap sync

That's a temporary solution, but better than nothing.

@arne-diegenbach
Copy link

Using Cordova the jalios branch works fine under Android 12 and 13 (didn't test others).
I believe Apache should merge this into the main branch urgently as of next month targeting SDK 33 is required for Android / Google PlayStore. Thanks all for the community effort to solve this.

@cyril23
Copy link

cyril23 commented Jul 3, 2023

@cyril23 Here a fork inspired from the work of https://github.com/jalios. Work perfectly on Android 13, 7 and 8 🎉

https://github.com/DaedalusDev/cordova-plugin-camera/

Thanks a lot for your work! I've tested it, too on the following the devices - everything works perfectly:

  • Android 7.0, Medion LifeTab X10302 (the only tablet in my tests)
  • Android 7.1.2, Zebra TC 25
  • Android 8.0.0, Samsung Galaxy S7
  • Android 8.1.0, Nexus 5X (LG H791)
  • Android 11, Newland NFT 10
  • Android 13, OnePlus 9 Pro
  • Android 13, Pixel 7
  • (iOS 16.5.1, iPhone 11 Pro)

Using Cordova the jalios branch works fine under Android 12 and 13 (didn't test others).
I believe Apache should merge this into the main branch urgently as of next month targeting SDK 33 is required for Android / Google PlayStore. Thanks all for the community effort to solve this.

yes, but I would recommend DaedalusDev' Branch on https://github.com/DaedalusDev/cordova-plugin-camera/ (I mean his merge request) because of its Android 7-8 downwards compability.

@cyril23
Copy link

cyril23 commented Jul 12, 2023

yes, but I would recommend DaedalusDev' Branch on https://github.com/DaedalusDev/cordova-plugin-camera/ (I mean his merge request) because of its Android 7-8 downwards compability.

By the way, the error 20 is still thrown if the camera permissions are not granted by the user (after requesting them by the app).

So with the current plugin, after the app requesting the permissions...

  • ... if the user permits both "Camera" and "Files and Media" permissions, pictures can be taken flawlessly
  • ... if the user denies either "Camera" and/or "Files and Media" permissions, an error 20 is thrown, without any additional information. In this case maybe a word about missing permissions would be helpful

Tested on Android 11 on a Newland NFT 10, I havn't tested any other devices or Android versions yet.

@nicholaszuccarelli
Copy link

+1 this is great. Need it merged!

@FlossyWeb
Copy link

+1 would be cool to merge, thanks for the fix.

FlossyWeb added a commit to FlossyWeb/cordova-plugin-camera that referenced this issue Aug 23, 2023
@vladretca
Copy link

+1 if you can prioritize this

@arne-diegenbach
Copy link

Please merge ASAP.

@TomPretorius
Copy link

I have tried ALL of these and still getting error 20 with API level 33

@LucasBourgeois
Copy link

@TomPretorius check that ure really using the fork instead of the apache release.

Yet, time limit is tomorrow and still no release of this fix... u can ask to google to delay the restriction a little bit (by 4 months if i remember right) and just have to wait the release of the fix..

Please consider to resolve and release a fix of this fast

@dovh-me
Copy link

dovh-me commented Sep 5, 2023

I have tried ALL of these and still getting error 20 with API level 33

Make sure you remove the existing cordova-plugin-camera before you install the mentioned one.
cordova plugin remove cordova-plugin-camera
cordova plugin add https://github.com/jalios/cordova-plugin-camera.git

Thanks for the fix @cyril23 😍

@breautek
Copy link
Contributor

breautek commented Sep 6, 2023

Should be fixed by #844

@breautek breautek closed this as completed Sep 6, 2023
@codingwithashu
Copy link

@cyril23 error is gone but the new error came "no image selected",
after taking the image click on the check icon, this error came

WhatsApp.Video.2023-09-21.at.14.39.34.-.Trim.mp4

@priyambadaBestinet
Copy link

not working with https://github.com/jalios/cordova-plugin-camera.git , camera not opening now.

@vikrantttriazinesoft
Copy link

  1. git clone https://github.com/apache/cordova-plugin-camera.git

  2. open the cordova-plugin-camera directory in any code editor

  3. search the cordova-android in project and then change cordova-android value to the version which is greater than yours cordova-android version used by you in your current project

  4. then install the plugin using :- cordova plugin add ./path_to cordova-plugin-camera ( directory )

  5. then run prepare command

  6. add
    in androidmanifest file

  7. add this in application tag of manifest file
    android:largeHeap="true" android:requestLegacyExternalStorage="true" android:usesCleartextTraffic="true"

  8. that's it

  9. now u can use the camera in ur cordova application

@vikrantttriazinesoft
Copy link

if u want to shift ur project to cordova-android 12
then the solution is
1 ionic cordova platform rm android
2 ionic cordova plugin rm cordova-plugin-camera
3 ionic cordova platform add android@12.0.0
4 cordova plugin add https://github.com/apache/cordova-plugin-camera.git
5 In project structure (Project) change
gradle plugin version : 7.1.2
gradle version : 7.5
6 In project structure (SDK Location) of Gradle Settings

Gradle Jdk :  corretto-17

@apache apache locked as resolved and limited conversation to collaborators Oct 16, 2023
@breautek
Copy link
Contributor

git clone https://github.com/apache/cordova-plugin-camera.git

Use current release instead of the tip of master of the development branch which will be unstable. At the time of writing, there has been no commits between the current release and the master branch outside of chore commits (e.g. bumping to 7.0.1-dev version) so if the master branch works, then so should 7.0.0.

android:largeHeap="true" android:requestLegacyExternalStorage="true" android:usesCleartextTraffic="true"

This is overall simply bad advice

android:largeHeap="true"

This will allow the Java heap to grow much larger than the standard 256mb the OS gives you. Garbage collection can be delayed and when GC does occur it can take a significantly longer time to accomplish leading to stuttering UI and poor app performance.

android:requestLegacyExternalStorage="true"

Today this is a no-op, it only applies if you're targeting API 29, and only applies if you had the app published before API 29 was released. Today, Google Play requires targeting API 33.

android:usesCleartextTraffic="true"

This should only be used in testing/development environments. Google expects you to be using secured traffic whenever possible so that your user data is properly secured.

I've locked this thread to respect the OP's inbox, because it seems to be going off topic (e.g. we can't provide assistance if you're using a fork of this plugin). If there are issues with v7 of this plugin, I'd recommend raising a new issue with the details filled out so that it can be tracked and addressed accordingly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests