title: Cordova runtime permissions
body: <p>I'm trying to get the user to enable the location group permission for my app with Cordova's hasPermission/requestPermission methods, but the results are confusing...</p>
  
  <p>When I call hasPermission with ACCESS_FINE_LOCATION, it always returns true. Calling this on Manifest.permission_group.LOCATION seems to return true/false appropriately. </p>
  
  <p>Calling requestPermission with Manifest.permission_group.LOCATION doesn't present a system dialog, so I'm calling this with ACCESS_FINE_LOCATION to get the dialog.</p>
  
  <p>The dialog Allow button turns on the Location group permission for my app and calls onRequestPermissionResult with PackageManager.PERMISSION_GRANTED, but the Deny button also returns ...GRANTED, leaving the Location group permission off.</p>
  
  <p>For illustration, here's my current code:</p>
  
  <pre><code>private void checkPermissions() {
      if (!cordova.hasPermission(Manifest.permission_group.LOCATION)) {
          cordova.requestPermission(this, PERMISSION_RUNTIME_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION);
      }
  }
  
  @Override
  public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
      if (permissions.length != 1 || grantResults.length != 1 || !Manifest.permission.ACCESS_FINE_LOCATION.equals(permissions[0])) {
          throw new RuntimeException("Unexpected permission results " + Arrays.toString(permissions) + ", " + Arrays.toString(grantResults));
      }
      int result = grantResults[0];
      String action = null;
      switch (result) {
          case PackageManager.PERMISSION_DENIED:
              action = Constants.ACTION_RUNTIME_PERMISSION_DENIED;
              break;
          case PackageManager.PERMISSION_GRANTED:
              action = Constants.ACTION_RUNTIME_PERMISSION_GRANTED;
              break;
          default:
              throw new RuntimeException("Unexpected permission result int " + result);
      }
  
      Intent i = new Intent(action);
      i.putExtra("permission", Constants.EXTRA_RUNTIME_PERMISSION_NOTIFICATION_ID);
      getContext().sendBroadcast(i);
  } 
  </code></pre>
  
  <p>What's the right way to handle this? Sometimes using an individual permission and sometimes using a group with these methods doesn't seem right - I would expect this to be consistent. My guess is that the PERMISSION_GRANTED after the DENY button is pushed on the dialog is because I'm requesting an individual permission, which is on even though the group is off; is there a way to detect that the user denied the request? </p>
  
  <p>I have a lot of questions there which basically boil down to "how do I either get the user to enable the Location group permission when it's off or know when they decline"?</p>
  
  <p>If it helps, my android-targetSdkVersion is set to 22, and I'm using Cordova 6.1.1.</p>