Get List of Installed Android Applications

How to get a list of installed android applications and pick one to run

Following is the code to get the list of activities/applications installed on Android :

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

You will get all the necessary data in the ResolveInfo to start a application. You can check ResolveInfo javadoc here.

How to get a list of installed apps on Android device

To comply with package visibility rules, you will need a <queries> element as a child of the root <manifest> element:

<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.action.LAUNCHER" />
</intent>
</queries>

How to get the list of apps that have been installed by a user on an Android device?

// Flags: See below
int flags = PackageManager.GET_META_DATA |
PackageManager.GET_SHARED_LIBRARY_FILES |
PackageManager.GET_UNINSTALLED_PACKAGES;

PackageManager pm = getPackageManager();
List<ApplicationInfo> applications = pm.getInstalledApplications(flags);
for (ApplicationInfo appInfo : applications) {
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// System application
} else {
// Installed by user
}
}

Flags:

  • GET_META_DATA
  • GET_SHARED_LIBRARY_FILES
  • GET_UNINSTALLED_PACKAGES

How to get list of ALL apps (including System Apps)?

You are already getting a list of all installed applications including the system apps by calling this:

List<ApplicationInfo> apps = getPackageManager().getInstalledPackages(0);

Those with the flags:

  • ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
  • ApplicationInfo.FLAG_SYSTEM

are system apps. You can check for the flags like this:

List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}

Get a list of installed applications in android

Use these methods in your activty to get a list of installed applications.

  private ArrayList<PackageInfoStruct> getPackages() {
ArrayList<PackageInfoStruct> apps = getInstalledApps(false);
final int max = apps.size();
for (int i=0; i < max; i++) {
apps.get(i);
}
return apps;
}

private ArrayList<PackageInfoStruct> getInstalledApps(boolean getSysPackages) {

List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
try{
app_labels = new String[packs.size()];
}catch(Exception e){
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
for(int i=0;i < packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PackageInfoStruct newInfo = new PackageInfoStruct();
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);

app_labels[i] = newInfo.appname;
}
return res;
}

Get list of installed android applications

I was working on something like this recently. One thing I'll say up front is to be sure and perform this in a separate thread -- querying the application information is SLOW. The following will get you a list of ALL the installed applications. This will include a lot of system apps that you probably aren't interested in.

PackageManager pm = getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);

To limit it to just the user-installed or updated system apps (e.g. Maps, GMail, etc), I used the following logic:

List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();

for(ApplicationInfo app : apps) {
//checks for flags; if flagged, check if updated system app
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
installedApps.add(app);
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
//Discard this one
//in this case, it should be a user-installed app
} else {
installedApps.add(app);
}
}

EDIT: Also, to get the name and icon for the app (which is probably what takes the longest -- I haven't done any real deep inspection on it -- use this:

String label = (String)pm.getApplicationLabel(app);
Drawable icon = pm.getApplicationIcon(app);

installedApps should have a full list of the apps you need, now. Hope this helps, but you may have to modify the logic a bit depending on what apps you need to have returned. Again, it is SLOW, but it's just something you have to work around. You might want to build a data cache in a database if it's something you'll be accessing frequently.

Get all installed apps in android 11 (API 30) , how to get all other apps installed in android 11?

From Android 11 Google has introduced a new permission to query all installed apps on android devices.
So if you want to get all applications in yours app for some reason then just add following permission in your manifest

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

or for specific category of apps you can use this in your manifest. for example if you want only apps with android.intent.category.HOME category then add this code.

<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent>
</queries>

also you can filter apps more specifically by adding more categories to it like shown below

<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME,android.intent.category.DEFAULT" />
</intent>
</queries>


Related Topics



Leave a reply



Submit