Example usage for android.content.pm PackageManager getPermissionGroupInfo

List of usage examples for android.content.pm PackageManager getPermissionGroupInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getPermissionGroupInfo.

Prototype

public abstract PermissionGroupInfo getPermissionGroupInfo(String name, @PermissionGroupInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve all of the information we know about a particular group of permissions.

Usage

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 .  ja  va 2s . 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);
    }
}