I wonder about this API design decision.
The current API forces us to save the callback context in some state
variable to have access to it
in the plugins `onRequestPermissionResult` like this:
private void requestPermissionAction(CallbackContext callbackContext,
JSONArray permission) {
this.permissionsCallback = callbackContext;
cordova.requestPermission(this, REQUEST_CODE_ENABLE_PERMISSION,
permission.getString(0));
}
@Override
public void onRequestPermissionResult(int requestCode, String[]
permissions, int[] grantResults) {
if (this.permissionsCallback == null) {
return;
}
if (permissions != null && permissions.length > 0) {
this.permissionsCallback.success();
} else {
this.permissionsCallback.error("No permission");
}
this.permissionsCallback = null;
}
This works but limits the concurrent calls to the plugins
`requestPermissionAction` to one caller from the script at a time (that
means until the success or error callbacks are called in the script).
Otherwise the `this.permissionCallback` would be set again for a second
call and when the first calls `onRequestPermissionResult` is called it will
actually call the handlers of the second `requestPermissionAction`
callbackContext.
Wouldn't this API signature make more sense?
cordova.requestPermission(CordovaPlugin plugin, int requestCode, String
permission, CallbackContext callbackContext);
@Override
public void onRequestPermissionResult(int requestCode, String[]
permissions, int[] grantResults, CallbackContext callbackContext) {
if (permissions != null && permissions.length > 0) {
permissionsCallback.success();
} else {
permissionsCallback.error("No permission");
}
}
And while we are at: Change `permission[]` and `grantResults[]` to an
object `results[permission] = grantResult`?