use of com.getcapacitor.annotation.CapacitorPlugin in project capacitor by ionic-team.
the class Plugin method requestAllPermissions.
/**
* Request all of the specified permissions in the CapacitorPlugin annotation (if any)
*
* If there is no registered permission callback for the PluginCall passed in, the call will
* be rejected. Make sure a valid permission callback method is registered using the
* {@link PermissionCallback} annotation.
*
* @since 3.0.0
* @param call the plugin call
* @param callbackName the name of the callback to run when the permission request is complete
*/
protected void requestAllPermissions(@NonNull PluginCall call, @NonNull String callbackName) {
CapacitorPlugin annotation = handle.getPluginAnnotation();
if (annotation != null) {
HashSet<String> perms = new HashSet<>();
for (Permission perm : annotation.permissions()) {
perms.addAll(Arrays.asList(perm.strings()));
}
permissionActivityResult(call, perms.toArray(new String[0]), callbackName);
}
}
use of com.getcapacitor.annotation.CapacitorPlugin in project capacitor by ionic-team.
the class Plugin method isPermissionDeclared.
/**
* Checks if the given permission alias is correctly declared in AndroidManifest.xml
* @param alias a permission alias defined on the plugin
* @return true only if all permissions associated with the given alias are declared in the manifest
*/
public boolean isPermissionDeclared(String alias) {
CapacitorPlugin annotation = handle.getPluginAnnotation();
if (annotation != null) {
for (Permission perm : annotation.permissions()) {
if (alias.equalsIgnoreCase(perm.alias())) {
boolean result = true;
for (String permString : perm.strings()) {
result = result && PermissionHelper.hasDefinedPermission(getContext(), permString);
}
return result;
}
}
}
Logger.error(String.format("isPermissionDeclared: No alias defined for %s " + "or missing @CapacitorPlugin annotation.", alias));
return false;
}
Aggregations