Android M - Camera permission denied returns 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.

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.

Answers


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)


Need Your Help

Codeigniter unable to load the requested file in a mobile device

php iphone codeigniter

I am getting a Unable to load the requested file: default.php error in codeigniter whenever i load up the website in a mobile device. It loads perfectly in desktop browser.

Possible to use Python with Intel's Atom Developer SDK (C/C++)?

python c visual-studio pygame intel-atom

So I've made a game in Python and PyGame. Now I'm interested in submitting the game to Intel's March Developer Challenge. However, the developer challenge requires use of Intel's Atom Developer SDK...