Example usage for android.content.pm PermissionGroupInfo loadLabel

List of usage examples for android.content.pm PermissionGroupInfo loadLabel

Introduction

In this page you can find the example usage for android.content.pm PermissionGroupInfo loadLabel.

Prototype

public @NonNull CharSequence loadLabel(@NonNull PackageManager pm) 

Source Link

Document

Retrieve the current textual label associated with this item.

Usage

From source file:Main.java

public static void printAllPermission(Context context) {
    if (!debug) {
        return;/* ww w. j a  va  2 s. com*/
    }
    PackageManager pm = context.getPackageManager();
    CharSequence csPermissionGroupLabel;
    CharSequence csPermissionLabel;
    List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.GET_PERMISSIONS);
    for (PermissionGroupInfo pgi : lstGroups) {
        csPermissionGroupLabel = pgi.loadLabel(pm);
        Log.d("ldx", "PermissionGroup: " + pgi.name + "  [" + csPermissionGroupLabel.toString() + "]");
        try {
            List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0);
            for (PermissionInfo pi : lstPermissions) {
                csPermissionLabel = pi.loadLabel(pm);
                Log.d("ldx", "     PermissionChild" + pi.name + "  [" + csPermissionLabel.toString() + "]");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:org.microg.tools.selfcheck.PermissionCheckGroup.java

private void doPermissionCheck(Context context, ResultCollector collector, final String permission) {
    PackageManager pm = context.getPackageManager();
    try {/* w w  w  .j  av a  2  s .  c o  m*/
        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);
    }
}

From source file:com.pranavpandey.smallapp.permission.PermissionDangerous.java

private void buildPermissionsDialog(final ArrayList<String> permissions, final boolean isRequest) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    View view = getLayoutInflater().inflate(R.layout.sas_dialog_permission, new LinearLayout(this), false);
    TextView message = (TextView) view.findViewById(R.id.permission_message);
    ViewGroup frame = (ViewGroup) view.findViewById(R.id.permission_frame);

    final ArrayList<String> permissionGroups = new ArrayList<String>();
    for (String permission : permissions) {
        try {/*from w  ww.  ja v a 2  s . c o m*/
            PermissionInfo permInfo = getPackageManager().getPermissionInfo(permission,
                    PackageManager.GET_META_DATA);
            if (!permissionGroups.contains(permInfo.group)) {
                permissionGroups.add(permInfo.group);
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    for (String permissionGroup : permissionGroups) {
        try {
            PermissionGroupInfo permGroupInfo = getPackageManager().getPermissionGroupInfo(permissionGroup,
                    PackageManager.GET_META_DATA);
            frame.addView(new PermissionItem(this, permGroupInfo.loadIcon(getPackageManager()),
                    permGroupInfo.loadLabel(getPackageManager()).toString(),
                    permGroupInfo.loadDescription(getPackageManager()).toString()));
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (isRequest) {
        message.setText(R.string.sas_perm_request_desc);
    } else {
        message.setText(String.format(getString(R.string.sas_format_next_line),
                getString(R.string.sas_perm_request_desc), getString(R.string.sas_perm_request_info)));
    }

    try {
        alertDialogBuilder.setIcon(
                DynamicTheme.createDialogIcon(this, getPackageManager().getApplicationIcon(getPackageName())));
    } catch (Exception e) {
        e.printStackTrace();
    }
    alertDialogBuilder.setTitle(getApplicationInfo().loadLabel(getPackageManager()).toString())
            .setPositiveButton(isRequest ? R.string.sas_perm_request : R.string.sas_perm_continue,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            if (isRequest) {
                                requestPermissions(permissions.toArray(new String[permissions.size()]));
                            } else {
                                openPermissionSettings(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            }
                        }
                    })
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    finishPermissionsChecker();
                }
            }).setCancelable(false);

    final AlertDialog dialog = alertDialogBuilder.create();
    dialog.setView(view, 0, SmallUtils.getDialogTopPadding(this), 0, 0);

    showPermissionDialog(dialog);
}

From source file:com.github.michalbednarski.intentslab.PermissionInfoFragment.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);/*  ww w .  ja  v a2s  .  c  o  m*/

    // Get system services
    mPm = getActivity().getApplicationContext().getPackageManager();

    final String permissionName = getArguments().getString(ARG_PERMISSION_NAME);

    // Get information about permission itself
    FormattedTextBuilder headerText = new FormattedTextBuilder();
    headerText.appendGlobalHeader(permissionName);
    try {
        final PermissionInfo permissionInfo = mPm.getPermissionInfo(permissionName, 0);

        headerText.appendGlobalHeader(String.valueOf(permissionInfo.loadLabel(mPm)));
        headerText.appendValue(getString(R.string.description),
                String.valueOf(permissionInfo.loadDescription(mPm)));

        try {
            if (permissionInfo.group != null) {
                headerText.appendValue(getString(R.string.permission_group_name), permissionInfo.group);
                final PermissionGroupInfo permissionGroupInfo = mPm.getPermissionGroupInfo(permissionInfo.group,
                        0);
                headerText.appendValueNoNewLine(getString(R.string.permission_group_label),
                        String.valueOf(permissionGroupInfo.loadLabel(mPm)));
                headerText.appendValueNoNewLine(getString(R.string.permission_group_description),
                        String.valueOf(permissionGroupInfo.loadDescription(mPm)));
            }
        } catch (PackageManager.NameNotFoundException ignored) {
        }

        headerText.appendValue(getString(R.string.permission_protection_level),
                protectionLevelToString(permissionInfo.protectionLevel));
        mDefinedBy = mPm.getPackageInfo(permissionInfo.packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        // Undeclared permission
        e.printStackTrace();
    }

    mDetailsText = headerText.getText();

    (new ScanUsingAppsTask()).execute(permissionName);
}