Cordova camera plugin permission denial in android

2019-04-12 19:19发布

问题:

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.

回答1:

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.



回答2:

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" >