20

Hi I want to get a list of all of the installed applications on the users device I have been googling for the longest time but can't find what i want this link was the closest though and works fine except me being new don't understand how to use the method getPackages(); and create a list with it

http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon

Any help on how to create the actual list would be a major help i have all that code already in just can't get the list to actually show thanks for any help

user577732
  • 3,956
  • 11
  • 55
  • 76
  • A lot of stuff but nothing that didn't force close or give me errors the method apparently returns an arraylist but being new to this i don't know how to display that in a list on the screen like a list view – user577732 May 28 '11 at 23:57

1 Answers1

68

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.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • no i'm mostly interested in the system apps actually i write root apps only so going to take a look at this now thanks – user577732 May 29 '11 at 03:04
  • Consider using an adapter. It will make the list scrolling choppier, but will load instantly, no matter how big is the list. – tacone Dec 29 '11 at 02:54
  • I want to access current running processes (user installed apps and system apps separately). Can you please help me? –  Apr 21 '13 at 06:43
  • 1
    Somehow I still got the system apps I am not sure why – Rohit Tigga Jul 21 '14 at 22:39
  • thanks a lot. Finally i found this answer as exact solution. It only shows the app that installed by user and simply ignoring app installed by device manufacturer. Gr8. keep it up. – Ripal Tamboli Sep 20 '14 at 06:04
  • 2
    There is one caveat: one application might have multiple activities that are 'launchable' (i.e. will show up on your device's home screen) and therefore you should consider using 'queryIntentActivities' instead. – Dan Borza Jan 09 '16 at 02:08
  • @RohitTigga i know it's old but you have to use `!= 0` instead of `==1` – TheMMSH Jul 24 '16 at 06:16
  • hey, @kevin On my real device(android version 12) getting an install app list take to time. – Abhi S Jun 30 '22 at 13:18