Example usage for android.content.pm PermissionGroupInfo loadDescription

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

Introduction

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

Prototype

public CharSequence loadDescription(PackageManager pm) 

Source Link

Document

Retrieve the textual description of this permission.

Usage

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  w w.j  a va 2 s.co  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);//  w  w w  .j  ava  2s  .com

    // 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);
}