ptia
ptia

Reputation: 141

Android get a list of all installed apps

I have obtained a list of installed app using this code:

public List<ResolveInfo>() {
    PackageManager pm=getPackageManager();
    Intent main=new Intent(Intent.ACTION_MAIN, null);

    main.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);

}

There is only a problem: it list only apps that has a MAIN activity. How can I get a List of all installed apps? Note that I used this code in a project that need that the List is of ResolveInfo, so please answer only code that returns a List of ResolveInfo.

Upvotes: 3

Views: 13309

Answers (2)

Guillermo Merino
Guillermo Merino

Reputation: 3257

Have you tried with:

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

(found here)

Upvotes: 9

kabuko
kabuko

Reputation: 36312

Your question doesn't quite make sense; you're making a bit of an unreasonable request. You say you want a list of all installed apps, but you also want a List of ResolveInfo objects. The docs of ResolveInfo describe it as:

Information that is returned from resolving an intent against an IntentFilter.

Apps and IntentFilters don't correlate one to one. What would you want the ResolveInfo objects to contain? If there's more than one for a package, which one would you want?

PackageManager does include a method getInstalledApplications, but it returns a List of ApplicationInfo objects which is a more appropriate type for this sort of query. Likewise there's a getInstalledPackages method as well that returns a List of PackageInfo objects.

Upvotes: 4

Related Questions