0

Is there a way to get list of all applications that use certain permission group? For example, if I have some permissions like Location, Camera or Contacts, I want to show the list of applications that use selected permission.

Here is the example image, so basically if I click on Location I want to show every installed app that use location permissions.

Thanks.

Permissions

    PackageManager packageManager = getContext().getPackageManager();
    List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(0);

    //Package name results
    ArrayList<String> packageList = new ArrayList<>();

    boolean isGranted;

    for (PackageInfo packageInfo : packageInfoList) {

        isGranted = PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, packageInfo.packageName);

        if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            //System apps
            continue;
        }

        if (isGranted) {
            packageList.add("" + packageInfo.applicationInfo.packageName);
        }
    }

    System.out.println("################# PACKAGES LIST: " + packageList);
alezniki
  • 185
  • 1
  • 14
  • 2
    Use `PackageManager` to iterate over all the installed packages (`getInstalledPackages()`), see what permissions they hold, and show the filtered result. – CommonsWare Mar 26 '18 at 16:54
  • Thanks @CommonsWare, So basically if I have something like this updated code, I will get only applications that have granted Location permissions. What if I want to get all application that needs Location permissions, regardless if they are granted or not. – alezniki Mar 27 '18 at 17:27
  • You should be looking at [the `requestedPermissions` field in the `PackageInfo` objects](https://developer.android.com/reference/android/content/pm/PackageInfo.html#requestedPermissions). – CommonsWare Mar 27 '18 at 17:38
  • @CommonsWare Can you show me in code please? – alezniki Mar 27 '18 at 17:59

0 Answers0