camera.getPicture returns error 20


#1

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.


#2

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.


#3

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?


#4

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.


#5

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