Android get a list of all installed apps

无人久伴 提交于 2019-12-07 13:30:22

问题


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 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.



来源:https://stackoverflow.com/questions/14510171/android-get-a-list-of-all-installed-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!