Java Code Examples for android.content.pm.PackageManager#getPermissionGroupInfo()
The following examples show how to use
android.content.pm.PackageManager#getPermissionGroupInfo() .
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: PermissionManager.java From QuickDevFramework with Apache License 2.0 | 5 votes |
/** * 获取权限所属权限组的名称 * <p>在需要显示某个权限所属的一组权限的名称时使用</p> */ public static String getPermissionGroupName(Context context, String permission) { PackageManager packageManager = context.getPackageManager(); try { PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0); PermissionGroupInfo permissionGroupInfo = packageManager.getPermissionGroupInfo(permissionInfo.group, 0); return permissionGroupInfo.loadDescription(packageManager).toString(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return permission; }
Example 3
Source File: AppInfoUtils.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 打印 APP 注册的权限 * @param packageName 应用包名 */ public static void printAppPermission(final String packageName) { try { StringBuilder builder = new StringBuilder(); // = PackageManager packageManager = AppUtils.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); String[] usesPermissionsArray = packageInfo.requestedPermissions; for (int i = 0; i < usesPermissionsArray.length; i++) { // 获取每个权限的名字, 如: android.permission.INTERNET String usesPermissionName = usesPermissionsArray[i]; // 拼接日志 builder.append("usesPermissionName = " + usesPermissionName); builder.append(NEW_LINE_STR); // 通过 usesPermissionName 获取该权限的详细信息 PermissionInfo permissionInfo = packageManager.getPermissionInfo(usesPermissionName, 0); // 获取该权限属于哪个权限组, 如: 网络通信 PermissionGroupInfo permissionGroupInfo = packageManager.getPermissionGroupInfo(permissionInfo.group, 0); // 拼接日志 builder.append("permissionGroup = " + permissionGroupInfo.loadLabel(packageManager).toString()); builder.append(NEW_LINE_STR); // 获取该权限的标签信息, 比如: 完全的网络访问权限 String permissionLabel = permissionInfo.loadLabel(packageManager).toString(); // 拼接日志 builder.append("permissionLabel = " + permissionLabel); builder.append(NEW_LINE_STR); // 获取该权限的详细描述信息, 比如: 允许该应用创建网络套接字和使用自定义网络协议 // 浏览器和其他某些应用提供了向互联网发送数据的途径, 因此应用无需该权限即可向互联网发送数据 String permissionDescription = permissionInfo.loadDescription(packageManager).toString(); // 拼接日志 builder.append("permissionDescription = " + permissionDescription); builder.append(NEW_LINE_STR); } // 打印日志 LogPrintUtils.dTag(TAG, builder.toString()); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "printAppPermission"); } }
Example 4
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; }