Following code snippet is what I am using in order to understand the permission set by the user as in newer android devices permissions can be tweaked for specific app from settings.
I want to alert a user to give permission to avoid app crashing But the following snippet is always returning true for me. What am I doing wrong?
//If authorisation not granted for camera
boolean permission = (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)==PackageManager.PERMISSION_GRANTED);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    //ask for authorisation
    //Manifest.permission.CAMERA
    if (ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.CAMERA)) {
        showExplanation("Permission Needed", "Rationale", Manifest.permission.CAMERA, REQUEST_PERMISSION_CAMERA);
    }
    else
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISSION_CAMERA);
}
else
    try {
        //releasing camera if it's already in use
        releaseCamera();
        camera = Camera.open(camId);
}catch (Exception e)
{
    e.printStackTrace();
}
 
     
    