Search in sources :

Example 6 with Permission

use of com.getcapacitor.annotation.Permission 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;
}
Also used : CapacitorPlugin(com.getcapacitor.annotation.CapacitorPlugin) Permission(com.getcapacitor.annotation.Permission)

Aggregations

CapacitorPlugin (com.getcapacitor.annotation.CapacitorPlugin)6 Permission (com.getcapacitor.annotation.Permission)6 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)2 JSONException (org.json.JSONException)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 ActivityResult (androidx.activity.result.ActivityResult)1 ActivityResultLauncher (androidx.activity.result.ActivityResultLauncher)1 ActivityResultContracts (androidx.activity.result.contract.ActivityResultContracts)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 ActivityCompat (androidx.core.app.ActivityCompat)1