List of usage examples for android.content.pm PermissionGroupInfo loadIcon
public Drawable loadIcon(PackageManager pm)
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 {/* w w w. j a v a 2s .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); }