问题
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.
回答1:
Have you tried with:
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
(found here)
回答2:
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 IntentFilter
s 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.
来源:https://stackoverflow.com/questions/14510171/android-get-a-list-of-all-installed-apps