camera.getPicture returns error 20

I’m building an Ionic 3 app for Android, and am using the camera plugin for choosing a pic from the camera or the photo gallery. It works fine when testing on Samsung Galaxy S4 running Android 5.1, and worked on the Android emulator as well as Nexus 6, but lately, instead of showing the gallery, it returns error message ‘20’ (no description, nada, just the number 20).
Here’s part of the code…

Camera.getPicture({
                quality : 75,
                destinationType : Camera.DestinationType.DATA_URL,
                sourceType : Camera.PictureSourceType.CAMERA,
                allowEdit : true,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 300,
                targetHeight: 300,
                saveToPhotoAlbum: false
            }).then(imageData => {
                this.base64Image = "data:image/jpeg;base64," + imageData;
                this.newRequest.photo = imageData;
                this.photo = this.base64Image;
            }, error => {
                console.log("ERROR -> " + JSON.stringify(error)); // This line shows ERROR -> 20
            });

This only happens on the emulator and Nexus 6 - it works fine on the Galaxy S4.
Any ideas or suggestions? Thanks.

Finally solved it from this solution Camera, ImagePicker permission to access media. It had to do with permissions. For some odd reason, this line

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

vanished from AndroidManifest.xml

I added it back and the photo gallery now pops up.

None of the solutions work for me. I’m using ionic 3 with the latest Cordova and few different plugins that are accessing camera: barcode, camera, and gallery plugin. Barcode and gallery are working fine. They prompt properly for the permissions and accessing fine.
Camera throws error 20. I tested on a couple different Android phones( one had 6 and one had 8) and the behavior was the same.
I tried also using the diagnostic plugin mentioned above and ask for external storage authorization. I’m getting success back.
Any ideas?

Have you tried removing the camera plugin and adding it again?
Also, make sure that AndroidManifest.xml has both
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">

and

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">

Good luck.

Actually, fixed it by implementing the solution from this thread:

1 Like
  1. git clone GitHub - apache/cordova-plugin-camera: Apache Cordova Plugin camera
  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

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 GitHub - apache/cordova-plugin-camera: Apache Cordova Plugin camera
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