Search in sources :

Example 1 with MyPermission

use of com.smartandroid.sa.entity.MyPermission in project SmartAndroidSource by jaychou2012.

the class AppInfo method getUsesPermission.

/**
	 * Get the App's All use Permission
	 * 
	 * @param packageName
	 * @return the use Permissions by ArrayList<MyPermission> permissions
	 */
public ArrayList<MyPermission> getUsesPermission(String packageName) {
    ArrayList<MyPermission> myPerms = new ArrayList<MyPermission>();
    try {
        PackageManager packageManager = c.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        String[] usesPermissionsArray = packageInfo.requestedPermissions;
        for (int i = 0; i < usesPermissionsArray.length; i++) {
            MyPermission permi = new MyPermission();
            // �õ�ÿ��Ȩ�޵�����,��:android.permission.INTERNET
            String usesPermissionName = usesPermissionsArray[i];
            permi.setPermissionName(usesPermissionName);
            System.out.println("usesPermissionName=" + usesPermissionName);
            // ͨ��usesPermissionName��ȡ��Ȩ�޵���ϸ��Ϣ
            PermissionInfo permissionInfo = packageManager.getPermissionInfo(usesPermissionName, 0);
            // ��ø�Ȩ�������ĸ�Ȩ����,��:����ͨ��
            PermissionGroupInfo permissionGroupInfo = packageManager.getPermissionGroupInfo(permissionInfo.group, 0);
            permi.setPermissionGroup(permissionGroupInfo.loadLabel(packageManager).toString());
            System.out.println("permissionGroup=" + permissionGroupInfo.loadLabel(packageManager).toString());
            // ��ȡ��Ȩ�޵ı�ǩ��Ϣ,����:��ȫ���������Ȩ��
            String permissionLabel = permissionInfo.loadLabel(packageManager).toString();
            permi.setPermissionLabel(permissionLabel);
            System.out.println("permissionLabel=" + permissionLabel);
            // ��ȡ��Ȩ�޵���ϸ������Ϣ,����:�����Ӧ�ô��������׽��ֺ�ʹ���Զ�������Э��
            // �����������ijЩӦ���ṩ���������������ݵ�;��,���Ӧ�������Ȩ�޼�����������������.
            String permissionDescription = permissionInfo.loadDescription(packageManager).toString();
            permi.setPermissionDescription(permissionDescription);
            System.out.println("permissionDescription=" + permissionDescription);
            System.out.println("===========================================");
            myPerms.add(permi);
        }
        return myPerms;
    } catch (Exception e) {
    }
    return myPerms;
}
Also used : PackageManager(android.content.pm.PackageManager) PermissionInfo(android.content.pm.PermissionInfo) MyPermission(com.smartandroid.sa.entity.MyPermission) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 PermissionGroupInfo (android.content.pm.PermissionGroupInfo)1 PermissionInfo (android.content.pm.PermissionInfo)1 MyPermission (com.smartandroid.sa.entity.MyPermission)1 ArrayList (java.util.ArrayList)1