1

I was trying to get all the package names of apps requesting permission SYSTEM_ALERT_WINDOW and add them to an ArrayList but it's returning null, I am new here. Here is my code.

//Initialize array list
    aList = new ArrayList<String>();
    //get packagemanager from activity
    PackageManager pm = getPackageManager();
    //get list of installed packages from package manager
    List<PackageInfo> info = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    //itirate for each package
    for(PackageInfo packageInfo : info) {
        //get array of PermissionInfo of each package once
        PermissionInfo[] permissionInfo = packageInfo.permissions;
            //check if array is not null
            if(permissionInfo!=null){
                //itirate for each permission
                for(PermissionInfo aPermission : permissionInfo) {
                    //check if a permission contains this string
                    if(aPermission.name.contains("SYSTEM_ALERT_WINDOW")) {
                        //if yes then add package name to drawers
                        aList.add(packageInfo.packageName);
                    }
                }
            }
    }

Can someone plz tell me what's going wrong?

swapfile3
  • 13
  • 1
  • 5
  • [`PackageInfo#permissions`](https://developer.android.com/reference/android/content/pm/PackageInfo#permissions) is for `` elements defined by the app itself. You want [`requestedPermissions`](https://developer.android.com/reference/android/content/pm/PackageInfo#requestedPermissions) instead (which is a `String[]`, btw). – Mike M. Apr 18 '20 at 09:23
  • hey thnx for replying, I want to get the name of package requesting the SYSTEM_ALERT_WINDOW permission no matter if the permission is granted or not. – swapfile3 Apr 18 '20 at 09:27
  • look at this => https://developer.android.com/reference/android/content/pm/PackageInfo#requestedPermissions – Harkal Apr 18 '20 at 09:31
  • Yeah, that's fine, you just need to check the right set. You want to check `requestedPermissions` instead. – Mike M. Apr 18 '20 at 09:31
  • 1
    hey @Mike M i tried requestedPermission and it worked like it's supposed to, thnx for the help. – swapfile3 Apr 18 '20 at 09:33

0 Answers0