[英]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. 只有一个问题:它只列出具有MAIN活动的应用程序。 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.
请注意,我在需要List为ResolveInfo的项目中使用此代码,因此请仅回答返回ResolveInfo列表的代码。
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. 您说您想要所有已安装应用的列表,但您还需要一个
ResolveInfo
对象List
。 The docs of ResolveInfo
describe it as: ResolveInfo
的文档将ResolveInfo
描述为:
Information that is returned from resolving an intent against an IntentFilter.
从解析针对IntentFilter的意图返回的信息。
Apps and IntentFilter
s don't correlate one to one. Apps和
IntentFilter
不会一对一关联。 What would you want the ResolveInfo
objects to contain? 你希望
ResolveInfo
对象包含什么? 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. PackageManager
确实包含一个方法getInstalledApplications
,但它返回一个ApplicationInfo
对象的List
,这是一种更适合这种查询的类型。 Likewise there's a getInstalledPackages
method as well that returns a List
of PackageInfo
objects. 同样,还有一个
getInstalledPackages
方法,它返回一个PackageInfo
对象的List
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.