Java Code Examples for android.content.pm.PermissionGroupInfo#loadLabel()

The following examples show how to use android.content.pm.PermissionGroupInfo#loadLabel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void doPermissionCheck(Context context, ResultCollector collector, final String permission) {
    PackageManager pm = context.getPackageManager();
    try {
        PermissionInfo info = pm.getPermissionInfo(permission, 0);
        PermissionGroupInfo groupInfo = info.group != null ? pm.getPermissionGroupInfo(info.group, 0) : null;
        CharSequence permLabel = info.loadLabel(pm);
        CharSequence groupLabel = groupInfo != null ? groupInfo.loadLabel(pm) : permLabel;
        collector.addResult(context.getString(R.string.self_check_name_permission, permLabel),
                context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED ? Positive : Negative,
                context.getString(R.string.self_check_resolution_permission, groupLabel),
                new SelfCheckGroup.CheckResolver() {

                    @Override
                    public void tryResolve(Fragment fragment) {
                        fragment.requestPermissions(new String[]{permission}, 0);
                    }
                });
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, e);
    }
}
 
Example 2
public static List<ApkPermission> parsePermissions(Context context, List<String> permissionArray) {
    List<ApkPermission> list = new ArrayList<>();
    CharSequence csPermissionGroupLabel;
    CharSequence csPermissionLabel;
    PackageManager pm = context.getPackageManager();

    List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.PERMISSION_GRANTED);
    for (String permission : permissionArray) {

        for (PermissionGroupInfo pgi : lstGroups) {
            try {
                List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, PackageManager.PERMISSION_GRANTED);
                for (PermissionInfo pi : lstPermissions) {
                    if (pi.name.equals(permission)) {
                        csPermissionLabel = pi.loadLabel(pm);
                        csPermissionGroupLabel = pgi.loadLabel(pm);
                        list.add(new ApkPermission(csPermissionGroupLabel.toString(), csPermissionLabel.toString()));
                    }
                }
            } catch (Exception e) {
                Logger.printException(e);
            }
        }
    }

    Collections.sort(list, new Comparator<ApkPermission>() {
        @Override
        public int compare(ApkPermission lhs, ApkPermission rhs) {
            return lhs.getName().compareTo(rhs.getName());
        }
    });

    return list;
}
 
Example 3
public static ArrayList<ApkPermission> permissions(Context context, ArrayList<String> permissionArray) {
    PackageManager pm = context.getPackageManager();

    CharSequence csPermissionGroupLabel;
    CharSequence csPermissionLabel;
    List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(0);
    ArrayList<ApkPermission> list = new ArrayList<>();

    if (permissionArray != null) {
        for (int i = 0; i != permissionArray.size(); i++) {
            String permission = permissionArray.get(i);

            for (PermissionGroupInfo pgi : lstGroups) {
                try {
                    List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0);
                    for (PermissionInfo pi : lstPermissions) {
                        if (pi.name.equals(permission)) {
                            csPermissionLabel = pi.loadLabel(pm);
                            csPermissionGroupLabel = pgi.loadLabel(pm);
                            list.add(new ApkPermission(csPermissionGroupLabel.toString(), csPermissionLabel.toString()));
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        Collections.sort(list, new Comparator<ApkPermission>() {
            @Override
            public int compare(ApkPermission lhs, ApkPermission rhs) {
                return lhs.getName().compareTo(rhs.getName());
            }
        });
    }

    return list;
}
 
Example 4
public static List<ApkPermission> parsePermissions(Context context,
    List<String> permissionArray) {
  List<ApkPermission> list = new ArrayList<>();
  CharSequence csPermissionGroupLabel;
  CharSequence csPermissionLabel;
  PackageManager pm = context.getPackageManager();

  List<PermissionGroupInfo> lstGroups =
      pm.getAllPermissionGroups(PackageManager.PERMISSION_GRANTED);
  for (String permission : permissionArray) {

    for (PermissionGroupInfo pgi : lstGroups) {
      try {
        List<PermissionInfo> lstPermissions =
            pm.queryPermissionsByGroup(pgi.name, PackageManager.PERMISSION_GRANTED);
        for (PermissionInfo pi : lstPermissions) {
          if (pi.name.equals(permission)) {
            csPermissionLabel = pi.loadLabel(pm);
            csPermissionGroupLabel = pgi.loadLabel(pm);
            list.add(new ApkPermission(csPermissionGroupLabel.toString(),
                csPermissionLabel.toString()));
          }
        }
      } catch (Exception e) {
        Logger.getInstance()
            .e(TAG, e);
        throw new RuntimeException(e);
      }
    }
  }

  Collections.sort(list, (lhs, rhs) -> lhs.getName()
      .compareTo(rhs.getName()));

  return list;
}