How to get all granted permissions of a app

I want to get all granted permissions. I know I can get all requested permissions by packageinfo.requestedPermissions but I want to know list of granted permissions and granted permissions can be lesser then requested in case of android M. So I just wanted to know that is there way that I can get list of all granted permissions?

I know from list of requested permission I can check for that permission weather granted or not but I want to know list of all granted permission. Don't want to check for every requested permission.


A simple function that returns all the permissions that have been requested and granted for a given package could look like this:

List<String> getGrantedPermissions(final String appPackage) {
    List<String> granted = new ArrayList<String>();
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(appPackage, PackageManager.GET_PERMISSIONS);
        for (int i = 0; i < pi.requestedPermissions.length; i++) {
            if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
                granted.add(pi.requestedPermissions[i]);
            }
        }
    } catch (Exception e) {
    }
    return granted;
}

Note that this requires API level 16 or above, but that should hopefully not be an issue these days.