我本周早些时候提出了类似的问题,但是我仍然不了解如何获取所有已安装应用程序的列表,然后选择一个运行。
我试过了:
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.
更多推荐
发布评论