如何获取安装的Android应用程序的列表,并选择一个运行(How to get a list of installed android applications and pick one to ru

编程入门 行业动态 更新时间:2024-10-26 08:31:57
如何获取安装的Android应用程序的列表,并选择一个运行(How to get a list of installed android applications and pick one to run)

我本周早些时候提出了类似的问题,但是我仍然不了解如何获取所有已安装应用程序的列表,然后选择一个运行。

我试过了:

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

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

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

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.

I've tried:

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

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

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上的活动/应用程序列表的代码:

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

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

HTH!

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);

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

更多推荐

本文发布于:2023-07-26 19:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   列表   list   Android   installed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!