Android M-拒绝摄影机权限会传回PERMISSION_GRANTED [英] Android M - Camera permission denied returns PERMISSION_GRANTED

查看:695
本文介绍了Android M-拒绝摄影机权限会传回PERMISSION_GRANTED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试对应用程序的拒绝权限,我发现当请求权限的状态时,它返回的是已授予而不是被拒绝.

I'm testing denial of permission to an application and I'm seeing that when asking for the state of the permission it returns granted instead of denied.

我正在根据Google指南检查权限状态:

I'm checking state of permissions according to Google's Guide:

    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                Manifest.permission.CAMERA)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(getActivity(),
                    new String[]{Manifest.permission.CAMERA},
                    PERMISSIONS_REQUEST_TAKE_PHOTO);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }

在以下情况下,它实际上是第一个返回的结果:

Here is what it actually returns in the first if:

状态"0"表示PackageManager.PERMISSION_GRANTED

State "0" means PackageManager.PERMISSION_GRANTED

这会产生一个java.lang.RuntimeException: Fail to connect to camera service错误.

DEVICE IS A NEXUS 5X

最诚挚的问候.

推荐答案

Quotig @CommonsWare:

Quotig @CommonsWare:

对于任何低于23的targetSdkVersion,即使用户在设置"中关闭了该权限组,您都应该获得PERMISSION_GRANTED.建议您完全卸载该应用程序,将targetSdkVersion设置为23,然后重试.

You're supposed to get PERMISSION_GRANTED for any targetSdkVersion below 23, even if the user toggled off that permission group in Settings. I suggest that you uninstall the app completely, set your targetSdkVersion to 23, and try it again.

这是解决方案.

(此评论将暂时标记为正确,直到评论者发布答案为止)

这篇关于Android M-拒绝摄影机权限会传回PERMISSION_GRANTED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆