如何获取已安装的 android 应用程序列表并选择一个运行 [英] How to get a list of installed android applications and pick one to run

查看:27
本文介绍了如何获取已安装的 android 应用程序列表并选择一个运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本周早些时候我问了一个与此类似的问题,但我仍然不明白如何获取所有已安装应用程序的列表,然后选择一个来运行.

I asked a similar question to this earlier this week but I'm still not understanding how to get a list of all installed applications and then pick one to run.

我试过了:

Intent intent = new Intent(ACTION_MAIN);
intent.addCategory(CATEGORY_LAUNCHER);

这仅显示预安装或可以运行 ACTION_MAIN Intent 类型的应用程序.

and this only shows application that are preinstalled or can run the ACTION_MAIN Intent type.

我也知道我可以使用 PackageManager 来获取所有已安装的应用程序,但是如何使用它来运行特定的应用程序?

I also know I can use PackageManager to get all the installed applications, but how do I use this to run a specific application?

推荐答案

以下是获取 Android 上安装的活动/应用程序列表的代码:

Following is the code to get the list of activities/applications installed on Android :

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

您将在 ResolveInfo 中获得启动应用程序所需的所有数据.你可以查看ResolveInfo javadoc 这里.

You will get all the necessary data in the ResolveInfo to start a application. You can check ResolveInfo javadoc here.

这篇关于如何获取已安装的 android 应用程序列表并选择一个运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆