Returns permissions' name (human-readable label) by permission key : Authentication « Security « Android






Returns permissions' name (human-readable label) by permission key

    
/*
 * Copyright (c) 2010.
 */

//package com.googlecode.securitywatch;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.net.Uri;
import android.os.Build;

/**
 * Utility class
 */
class Utils {

    public static boolean hasPermission(String packageName, String permission, final PackageManager pkgmanager) {
        return PackageManager.PERMISSION_GRANTED == pkgmanager.checkPermission(permission, packageName);
    }

    /**
     * Returns permissions' name (human-readable label) by permission key
     */
    static CharSequence getPermissionLabel(String permission, PackageManager packageManager) {
        try {
            PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0);
            return permissionInfo.loadLabel(packageManager);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }


    private CharSequence getPermissionDescription(String permission, PackageManager packageManager) {
        try {
            PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0);
            return permissionInfo.loadDescription(packageManager);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

}

   
    
    
    
  








Related examples in the same category

1.Web authentication Confirmation
2.Provides symmetric key cryptography and hashing.