以编程方式列出 android 中已安装/正在运行的应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11391451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:14:58  来源:igfitidea点击:

List out installed/running applications in android programmatically

android

提问by Sathish Sathish

Possible Duplicate:
How to get a list of installed android applications and pick one to run

可能的重复:
如何获取已安装的 android 应用程序列表并选择一个运行

We have using a android mobile.

我们使用的是安卓手机。

  1. How to list out All Installed Applications.
  2. How to list out All Running Applications.
  1. 如何列出All Installed Applications
  2. 如何列出All Running Applications

Help Me. Thanks.

帮我。谢谢。

回答by Ponmalar

To get the list of activities/applications installed on Android:

要获取 Android 上安装的活动/应用程序列表:

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

Referred from: How to get a list of installed android applications and pick one to run

引用自:如何获取已安装的 android 应用程序列表并选择一个运行

To check all running applications

检查所有正在运行的应用程序

ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();

Referred From: http://www.dreamincode.net/forums/topic/138412-android-20-list-of-running-applications/

引用自:http: //www.dreamincode.net/forums/topic/138412-android-20-list-of-running-applications/

Note: Above described function will return correct result for below API 21, for 21 and above it's deprecated.

注意:对于低于 API 21 的上述函数将返回正确的结果,对于 21 及以上版本已弃用。