Get list of apps of all users Get list of apps of all users android android

Get list of apps of all users


I found the code for the ParceledListSlice here, and the code for the Parcelable interface it implements here. It looks like it uses some form of array internally, so you should be able to iterate over that. I can't actually say if this will be helpful to you or not, because I'm not all that familiar with these Libraries, but I hope it's a starting point. Good Luck!


You can apply the approach you mentioned in your first EDIT and EDIT2 and use Android's shell, since you mentioned your device has root permissions.

By the way, I'm not familiar with the library from "stericson" you are using, but I agree with leveraging existing libraries to make your life easier; I am using libsuperuser. Otherwise, you can write code to run shell commands using Process etc. yourself (but there are lots of things to consider with handling error output, closing objects, and so forth).

private List<String> listAllInstalledApps(){    String user = "0"; //can modify to iterate over all users     if (Shell.SU.available()) {        //grab user installed package names        List<String> output =            Shell.SU.run("pm list packages --user " + user + " -3");        StringBuilder csvBuilder = new StringBuilder();        for(String item : output){            csvBuilder.append(item);            csvBuilder.append(", ");        }        Log.info(TAG, "Obtained installed apps: " + csvBuilder.toString());        return output;    }    return new ArrayList<>();}

Of course, you can use other arguments to pm as necessary such as -e, -d see documentation.

Once you extract the package names, get all required info (as is contained in ApplicationInfo) using dumpsys

//package names extracted from List<String> you returned earlierfor( String name : packageNames ){    List<String> appInfo =            Shell.SU.run("dumpsys package " + name);    //search appInfo for info you need e.g. grantedPermissions, targetSdk...}

Create ApplicationInfo objects as required, if you have downstream code that requires this object type specifically

ApplicationInfo info = new ApplicationInfo();info.uid = uid;info.processName = processName;info.className = classname;info.packageName = packageName;info.minSdkVersion = minSdkVersion;//etc...

(fields of the ApplicationInfo class are public). This is also true of PackageInfo which is an object that contains an ApplicationInfo field, plus it contains details of the install time etc. which are also details you can extract from the dumpsys output. So you could create an array of these as you wish and can be populated with your new ApplicationInfo objects.


private static JSONArray getAllAppNames() {        JSONArray appNameList = new JSONArray();        List<PackageInfo> packs = GlobalApplication.getContextOfApplication().getPackageManager().getInstalledPackages(0);        for (int i = 0; i < packs.size(); i++) {            PackageInfo p = packs.get(i);            if ((!isSystemPackage(p))) {                String appName = p.applicationInfo.loadLabel(GlobalApplication.getContextOfApplication().getPackageManager()).toString();                appNameList.put(appName);            }        }        return appNameList;    }    private static boolean isSystemPackage(PackageInfo pkgInfo) {        return (pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;    }

This should more or less solve your basic problem