Get installed Applications with Name, Package Name, Version and Icon

10 votes · 12 comments

This helper function retrieves all installed apps with the application name, package name, version-number and -code as well as the icons. The method getPackages() returns an ArrayList with all the apps.

raw ·
copy
· download
class PInfo { private String appname = ""; private String pname = ""; private String versionName = ""; private int versionCode = 0; private Drawable icon; private void prettyPrint() { Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode); } } private ArrayList<PInfo> getPackages() { ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */ final int max = apps.size(); for (int i=0; i<max; i++) { apps.get(i).prettyPrint(); } return apps; } private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) { ArrayList<PInfo> res = new ArrayList<PInfo>(); 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); } return res; }
Add a comment

12 Comments

Nice post,

Thanks for bringing this up

Reply · Aug. 28, 2009, 8:19 p.m.

thansk for the help! its working perfectly!

Reply · March 24, 2011, 9:11 a.m.

i cant get it to work at all, what must you do to get it to work?

Reply · March 24, 2011, 10:06 p.m.

It depends what you want to do, but you can use getPackages() to return you an ArrayList of all the installed items.

Reply · March 24, 2011, 11:09 p.m.

if you are getting error in Log.v(appname + "t" + pname + "t" + versionName + "t" + versionCode); then replace this line with System.out.println(appname + "t" + pname + "t" + versionName) + "t" + versionCode + "t");

Reply · March 25, 2011, 4:58 a.m.

I'm very new to Android development and I'm not really sure how to use this snippet. Would someone please provide me with an example? (Maybe a blank gui using this?)

Thanks!

Reply · April 6, 2011, 2:40 p.m.

Hi, been working on your snippets for quite some time now and unfortunately, it does show system apps, no matter what I do.

Tried modifying the continue statement to: if ((packs.get(i).versionCode & ApplicationInfo.FLAG_SYSTEM) == 1 && !getSysPackages) { continue; } it does screen most system apps but not all of them and also removes some user installed apps, so it's no good...

Would love if you can update you code or tell me what i'm missing here :)

Reply · Sept. 27, 2011, 9:04 p.m.

Never mind, here is the right if statement: if ((packs.get(i).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { continue; }

Thank you for the rest of the great code!

Reply · Sept. 27, 2011, 9:09 p.m.

Can you mention the packages that you imported ?

Reply · Nov. 18, 2011, 11:48 p.m.

Can you mention the packages that you imported ?

Reply · Nov. 18, 2011, 11:49 p.m.

very very good thank you for giving such a nice code fabulous....it's save my time

Reply · June 6, 2014, 6:10 p.m.

Hi using p.versionname= null is pulling few apps installed by google how to avoid it and just get list of user installed apps

Reply · Aug. 17, 2014, 7:06 p.m.