Android:Getting List of Application's package info which has been installed as a Device administrator

1k Views Asked by At

I need to get the list of package info for application which has been installed as Device admin. The code you share should support from Adroid Api version 8.

The following code will give me the list of Downloaded apps info, but i need an extra filter in the list as the app should be Device admin enabled app

List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p = packs.get(i);
        if ((!getSysPackages) && (p.versionName == null)) {
            continue ;
        }
        PInfo newInfo = new PInfo();
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        newInfo.pname = p.packageName;
        newInfo.versionName = p.versionName;
        newInfo.versionCode = p.versionCode;
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
        res.add(newInfo);
    }

Thanks in Advance

2

There are 2 best solutions below

1
On

We will get list of apps use this

final PackageManager pm = getPackageManager(); 
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    Log.d(TAG, "Installed package :" + packageInfo.packageName);   
}
0
On

Here the solution :

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
List<ComponentName> activeAdmins =   devicePolicyManager.getActiveAdmins();
if (activeAdmins != null){
   for (ComponentName admin : activeAdmins){
            admin.getPackageName();                  
           }
}