2
votes

I am using ionic to develop a mobile application. The application requires camera. I added Cordova camera plugin to my project. Also I am using ngCordova wrapper. The application was working fine. Last day I used one device with android version 6.0 (Marshmallow) to test my app. when I click on the button it directly triggers the error. I done USB debugging, I got the error that

Camera Error  "Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Android/data/com.app.cameratest/cache/.Pic.jpg} (has extras) } from ProcessRecord{6fe7446 18933:com.app.cameratest/u0a471} (pid=18933, uid=10471) with revoked permission android.permission.CAMERA"

I googled it and found that in android 6.0, the permissions are disabled by default and when the time of attempting to access camera, it will ask for permission. I didn't get any permission seeking dialog box for camera. But I got the permission prompt for location plugin and file plugin.

My Cordova version is 6.0 camera plugin version 2.1.0 Cordova android API 23

I tried downgrading the Cordova Android version to 5.0 for changing target version to android 22.

Here is my code

var options = {
            quality: 75,
            destinationType: Camera.DestinationType.FILE_URI,
            sourceType: 1,
            allowEdit: false,
            encodingType: 0,
            targetWidth: 380,
            targetHeight: 450,
            popoverOptions: CameraPopoverOptions,
            direction: 1,
            saveToPhotoAlbum: true
        };
 $cordovaCamera.getPicture(options).then(function(imageData) {
   console.log('image data': imageData);
},function(error) {
    console.error('Camera Error ', JSON.stringify(error));
 });

I tried updating the plugin to 2.1.1; still not working. If any one have any solution for that, please share. I don't know why this plugin doesn't ask for permission prompt.

The camera is working if we manually enable the permission of camera in settings menu. I don't want to interrupt the user flow in my application for that.

2
did you have a look at this - issues.apache.org/jira/browse/CB-10120 - Gandhi
@Gandhi : I have already seen the post. They reported is as a security issue. But the plugin is not updated to handle this issue. I am not good at java to write codes for plugin. Do you have any forked plugin to suggest, which handles this issue. ? - SANGEETH KUMAR S G
sorry i m not sure about forked plugins as i dont have hand on experience on them. Have a look at this post once - stackoverflow.com/questions/34784460/… - Gandhi
i encountered permission issue in file plugin with android marshmallow, but it got fixed later in plugin itself.Now on first file it does prompts me for permission to access.Even in camera plugin,permission issues are fixed.So i m still not sure whether you have up-to-date files in plugin and did readded android platform after removal? - Gandhi
Try installing latest version of the plugin from github cordova plugin add https://github.com/apache/cordova-plugin-camera - jcesarmobile

2 Answers

2
votes

Thank you guys. The problem is fixed. The problem was with my cordova version. I was using cordova 6.0.0 . Now I updated the cordova version to latest (6.1.1). Now it is asking for permission. Thank you for your support.

0
votes

If another fellow is breaking his head with this, only this works for me:

Only by adding this tag to config. < preference name="android-targetSdkVersion" value="22" >