Java Code Examples for android.content.pm.PermissionInfo#loadLabel()
The following examples show how to use
android.content.pm.PermissionInfo#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
Source File: PermissionCheckGroup.java From android_external_MicroGUiTools with Apache License 2.0 | 8 votes |
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
Source File: Permissions.java From BlackList with Apache License 2.0 | 6 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 3
Source File: OpsLabelHelper.java From AppOpsXposed with GNU General Public License v3.0 | 6 votes |
private static String getPermissionLabel(Context context, String permission, String defValue) { try { final PackageManager pm = context.getPackageManager(); final PermissionInfo pi = pm.getPermissionInfo(permission, 0); final CharSequence label = pi.loadLabel(pm); if(label != null && !label.toString().equals(permission)) return label.toString(); } catch(NameNotFoundException e) { // om nom nom } return defValue; }
Example 4
Source File: AptoideUtils.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
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 5
Source File: PermissionsActivity.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
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 6
Source File: AptoideUtils.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
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; }
Example 7
Source File: DataMoveActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
private void askForPermission() { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { String name; try { PackageManager pm = getPackageManager(); PermissionInfo permissionInfo = pm.getPermissionInfo(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.GET_META_DATA); name = (String) permissionInfo.loadLabel(pm); } catch (PackageManager.NameNotFoundException e) { logger.error("Failed to obtain name for permission", e); name = "read external storage"; } new AlertDialog.Builder(this) .setMessage(getString(R.string.msgWriteExternalStorageRationale, name)) .setPositiveButton(R.string.ok, (dialog, which) -> requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE)) .setNegativeButton(R.string.cancel, (dialog, which) -> finish()) .create() .show(); } else { requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } } else { mDataMoveFragment.startDataMove(); } }
Example 8
Source File: DataImportActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
private void askForPermission(Runnable task) { mTask = task; if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) { String name; try { PackageManager pm = getPackageManager(); PermissionInfo permissionInfo = pm.getPermissionInfo(Manifest.permission.READ_EXTERNAL_STORAGE, PackageManager.GET_META_DATA); name = (String) permissionInfo.loadLabel(pm); } catch (PackageManager.NameNotFoundException e) { logger.error("Failed to obtain name for permission", e); name = "read external storage"; } new AlertDialog.Builder(this) .setMessage(getString(R.string.msgReadExternalStorageRationale, name)) .setPositiveButton(R.string.ok, (dialog, which) -> requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE)) .setNegativeButton(R.string.cancel, (dialog, which) -> finish()) .create() .show(); } else { requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); } } else { mDataImportFragment.startImport(mTask); } }
Example 9
Source File: ReportDisplay.java From exodus-android-app with GNU General Public License v3.0 | 4 votes |
public static ReportDisplay buildReportDisplay(Context context, ApplicationViewModel model, PackageManager manager, PackageInfo info) { ReportDisplay reportDisplay = new ReportDisplay(); reportDisplay.packageName = model.packageName; reportDisplay.versionName = model.versionName; reportDisplay.versionCode = model.versionCode; reportDisplay.displayName = model.label.toString(); reportDisplay.report = model.report; reportDisplay.trackers = model.trackers; if (reportDisplay.report != null) reportDisplay.creator = DatabaseManager.getInstance(context).getCreator(reportDisplay.report.appId); List<Permission> requestedPermissions= new ArrayList<>(); if (info.requestedPermissions != null) { for(int i = 0; i < info.requestedPermissions.length; i++) { Permission permission = new Permission(); permission.fullName = info.requestedPermissions[i]; try { PermissionInfo permissionInfo = manager.getPermissionInfo(permission.fullName,PackageManager.GET_META_DATA); if(permissionInfo.loadDescription(manager) != null) permission.description = permissionInfo.loadDescription(manager).toString(); if(permissionInfo.loadLabel(manager) != null) permission.name = permissionInfo.loadLabel(manager).toString(); permission.dangerous = permissionInfo.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS; if(permission.fullName.equals(Manifest.permission.WRITE_SETTINGS) || permission.fullName.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) //Special permissions permission.dangerous = true; if (permissionInfo.group != null) { PermissionGroupInfo permissionGroupInfo = manager.getPermissionGroupInfo(permissionInfo.group, PackageManager.GET_META_DATA); if(permissionGroupInfo.loadIcon(manager) != null) permission.icon = permissionGroupInfo.loadIcon(manager); } } catch (PackageManager.NameNotFoundException e) { e.getLocalizedMessage(); } requestedPermissions.add(permission); } } reportDisplay.permissions = requestedPermissions; reportDisplay.logo = model.icon; return reportDisplay; }