Android M - Camera permission denied returns PERMISSION_GRANTED

 ̄綄美尐妖づ 提交于 2019-12-11 12:48:39

问题


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.

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:

State "0" means PackageManager.PERMISSION_GRANTED

This is generating a java.lang.RuntimeException: Fail to connect to camera service error.

DEVICE IS A NEXUS 5X

Best regards.


回答1:


Quotig @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.

This was the solution.

(This answer will be marked correct temporarily until commenter posts an answer)



来源:https://stackoverflow.com/questions/34052881/android-m-camera-permission-denied-returns-permission-granted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!