title: Android Runtime Permissions Not Working
body: <p>This is my code to ask runtime CAMERA permission in Android. I call <code>handleCameraPermission()</code> from my <code>onCreate()</code>.</p>
  
  <p>When I run my app for the first time, the permission is automatically enabled. I went to settings and disabled the permission. But still the <code>checkIfPermissionEnabled()</code> returns true but the camera doesn't start. So, what is the problem with <code>checkIfPermissionEnabled()</code>?</p>
  
  <p>When I set <code>hasCameraPermission = false</code> and executed the code, there was no dialog box but the camera permission got enabled and everything was fine.</p>
  
  <pre><code>private boolean checkIfPermssionEnabled() {
      int result = ContextCompat.checkSelfPermission(context, android.Manifest.permission.CAMERA);
      if(result == PackageManager.PERMISSION_GRANTED)
          return true;
      return false;
  }
  
  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
      switch (requestCode) {
          case CAMERA_PERMISSION_REQUEST:
              if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  //granted
                  hasCameraPermission = true;
              } else {
                  //not granted
                  hasCameraPermission = false;
                  super.onBackPressed();
              }
              break;
          default:
              super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      }
  }
  
  private void handleCameraPermission() {
      int myVersion = Build.VERSION.SDK_INT;
      if(myVersion &gt;= Build.VERSION_CODES.M) {
          hasCameraPermission = checkIfPermssionEnabled();
          if(!hasCameraPermission) {
              Log.d("cam","cam no permission");
              //if(ActivityCompat.shouldShowRequestPermissionRationale(activity,android.Manifest.permission.CAMERA)) {
                  ActivityCompat.requestPermissions(activity,new String[]{android.Manifest.permission.CAMERA},CAMERA_PERMISSION_REQUEST);
                  Log.d("cam","cam dialog permission showed");
              }
              //else {
              //  ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST);
              //}
          } else
              Log.d("cam","cam has permission");
      } else
          hasCameraPermission = true;
  }
  </code></pre>
  
  <p>What I am trying to acheive is if the camera permission is not enabled, the default dialog box for asking permission should appear and I should get callbacks for the user's input i.e., get notified is user pressed Deny or Allow.</p>