Android M - 相机权限被拒绝返回PERMISSION_GRANTED

时间:2015-12-02 21:00:00

标签: android android-camera android-6.0-marshmallow

我正在测试拒绝某个应用程序的权限,并且我在查询权限时会看到它返回授予而不是拒绝。

enter image description here

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

    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.
        }
    }

以下是第一个if:

实际返回的内容

enter image description here

州" 0"表示PackageManager.PERMISSION_GRANTED

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

DEVICE IS A NEXUS 5X

最好的问候。

1 个答案:

答案 0 :(得分:2)

Quotig @CommonsWare:

  

您应该为23以下的任何targetSdkVersion获取PERMISSION_GRANTED,即使用户在“设置”中切换了该权限组也是如此。我建议您完全卸载应用程序,将targetSdkVersion设置为23,然后再次尝试。

这是解决方案。

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