Java Code Examples for android.content.pm.PackageManager.getPermissionInfo()

The following are Jave code examples for showing how to use getPermissionInfo() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BlackList   File: Permissions.java   View Source Code Vote up 7 votes
/**
 * Returns information string about permission
 **/
@Nullable
private static String getPermissionInfo(@NonNull Context context, @NonNull String permission) {
    context = context.getApplicationContext();
    PackageManager pm = context.getPackageManager();
    PermissionInfo info = null;
    try {
        info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ex) {
        Log.w(TAG, ex);
    }

    if (info != null) {
        CharSequence label = info.loadLabel(pm);
        if (label == null) {
            label = info.nonLocalizedLabel;
        }
        return label.toString();
    }

    return null;
}
 
Example 2
Project: FirebasePost   File: PermissionsHelper.java   View Source Code Vote up 6 votes
/**
 * use for get {@link PermissionInfo} of all @param required
 *
 * @param context
 * @param required
 * @return
 */
private static List<PermissionInfo> getPermissions(Context context, List<String> required) {

    List<PermissionInfo> permissionInfoList = new ArrayList<>();

    PackageManager pm = context.getPackageManager();
    for (String permission : required) {
        PermissionInfo pinfo = null;
        try {
            pinfo = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            continue;
        }

        permissionInfoList.add(pinfo);
    }
    return permissionInfoList;
}
 
Example 3
Project: Brevent   File: OpsItemAdapter.java   View Source Code Vote up 5 votes
private PermissionInfo getPermissionInfo(PackageManager packageManager, String permission) {
    if (TextUtils.isEmpty(permission)) {
        return null;
    }
    try {
        return packageManager.getPermissionInfo(permission, 0);
    } catch (PackageManager.NameNotFoundException e) {
        UILog.w("Can't find permission " + permission, e);
        return null;
    }
}
 
Example 4
Project: Rationale   File: PermissionDetails.java   View Source Code Vote up 5 votes
public PermissionDetails getPermissionDetails(Context context, String permission, int permissionDrawableResID) {
    PackageManager pm = context.getPackageManager();
    PermissionInfo info = null;
    try {
        info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
        String text = info.loadDescription(context.getPackageManager()).toString();
        this.permission = permission;
        this.description = text;
        this.protectionLevel = info.protectionLevel;
        this.drawableResId = permissionDrawableResID;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return this;
}