将已安装的应用程序放入listView [英] get installed applications into a listView
本文介绍了将已安装的应用程序放入listView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将所有已安装的应用程序列在listView
中.
我尝试了以下代码和其他代码,但效果不佳
How can I get all installed applications listed into a listView
.
I tried the following code and others but it does not work well
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
}
而且我仍然不明白为什么要以这种方式使用意图.
and I'm still not understanding why to use intent in this manner.
推荐答案
您可以执行以下操作:
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.e(TAG, "Installed package :" + packageInfo.packageName);
Log.e(TAG, "Source dir : " + packageInfo.sourceDir);
Log.e(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
Log.e(TAG, "");
}
使用程序包列表文件
我总是使用此代码,希望您喜欢
i always use this code , i hope you enjoy it
这篇关于将已安装的应用程序放入listView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文