3

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.

jprofitt
  • 10,874
  • 4
  • 36
  • 46
ptia
  • 141
  • 2
  • 3
  • 14
  • 1
    Well, I didn't downvote it, but for starters, what you want is impossible. You cannot get a list of installed applications in the form of a `List` of `ResolveInfo` objects. – CommonsWare Jan 24 '13 at 20:36
  • You likely got downvoted because your last sentence could be interpreted as a "give me code" request, rather than "please help me with my existing code." I didn't downvote either, but if I had to guess that may be why. – jprofitt Jan 24 '13 at 21:32

2 Answers2

9

Have you tried with:

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

(found here)

Community
  • 1
  • 1
Guillermo Merino
  • 3,197
  • 2
  • 17
  • 34
4

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.

kabuko
  • 36,028
  • 10
  • 80
  • 93