Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all granted permissions of a app

Tags:

android

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.

like image 291
HariRam Avatar asked May 18 '16 08:05

HariRam


People also ask

Can apps bypass permissions?

Android apps must ask for permission to access sensitive resources on the phone, like the GPS, the camera, or the user's contacts data. When you say that an app can't access your location data, the operating system can prevent it from doing so because it runs the app in its own sandbox.


1 Answers

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.

like image 106
Michael Avatar answered Oct 03 '22 07:10

Michael