在Android 6.0中Cordova相机插件权限拒绝

问题描述:

我正在使用ionic来开发移动应用程序。该应用程序需要相机。我在我的项目中添加了Cordova相机插件。我也在使用ngCordova包装器。该应用程序运行正常。最后一天,我使用一个设备与Android版6.0(Marshmallow)来测试我的应用程序。当我点击按钮时,它会直接触发错误。我做了USB调试,我收到错误

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"

我用谷歌搜索它,发现在android 6.0中,默认情况下禁用权限,并在尝试访问时相机,它会要求许可。我没有得到任何寻求相机对话框的权限。但我获得了位置插件和文件插件的权限提示。

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.

我的Cordova版本是6.0
相机插件版本2.1.0
Cordova android API 23

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

我尝试将Cordova Android版本降级为5.0,将目标版本更改为Android 22。

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

这是我的代码

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));
 });

我尝试将插件更新为2.1.1;还是行不通。如果任何人有任何解决方案,请分享。我不知道为什么这个插件不会要求许可提示。

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.

谢谢你们。问题是固定的。问题出在我的cordova版本上。我使用的是cordova 6.0.0。现在我将cordova版本更新为最新版本(6.1.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.