获取Android的活跃应用程序的名称应用程序、活跃、名称、Android

2023-09-12 09:04:06 作者:百撕不得骑姐

我试图做一个程序,显示所有的活动应用程序。

I am trying to make a program that shows all the active applications.

我到处找,但只能找到code,显示在包的名称只。

I searched everywhere but could only find code that shows the package name only.

这将是很大的帮助,如果你高手能告诉我如何显示所有活动的应用程序名

It would be of great help if you masters can tell me how to display all the active application name

推荐答案

你有没有尝试使用 ActivityManager.getRunningAppProcesses()? 下面是示例code检索名称:

Did you try using ActivityManager.getRunningAppProcesses()? Here is the sample code for retrieving names:

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext()) {
  ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
  try {
    CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
    Log.w("LABEL", c.toString());
  }catch(Exception e) {
    //Name Not FOund Exception
  }
}