Android M - 相机权限被拒绝 returns PERMISSION_GRANTED

Android M - Camera permission denied returns PERMISSION_GRANTED

我正在测试对应用程序的拒绝权限,我在询问权限状态时看到它 returns 授予而不是拒绝。

我正在根据 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 中 returns 的实际情况:

状态“0”表示PackageManager.PERMISSION_GRANTED

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

DEVICE IS A NEXUS 5X

此致。

引用@CommonsWare:

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.

这就是解决方案。

(在评论者发布答案之前,此答案将被暂时标记为正确)