2

I want to show the list of applications installed on user device which have the internet permission on their manifest file currently I am getting all of them by using this code:

PackageManager packageManager = mainActivity.getPackageManager();
            apps = packageManager.getInstalledApplications(0);
            Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(packageManager));
Cœur
  • 37,241
  • 25
  • 195
  • 267
kamran hatami
  • 122
  • 1
  • 8

1 Answers1

3

Instead of getInstalledApplications(), use getInstalledPackages(), including GET_PERMISSIONS in the flags. The resulting PackageInfo objects will have a permissions field filled in, for those packages that request permissions. permissions will be a PermissionInfo[], and PermissionInfo has a name field you can check to see if it matches your desired permission. Something like this should work:

for (PackageInfo pkg : mgr.getInstalledPackages(PackageManager.GET_PERMISSIONS)) {
  for (PermissionInfo perm : pkg.permissions) { 
    if (Manifest.permission.INTERNET.equals(perm.name)) {
      // do something
    }
  }
}
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491