获取Android的活跃应用程序的名称 [英] Get active Application name in Android

查看:167
本文介绍了获取Android的活跃应用程序的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

你有没有尝试使用 <一个href="http://developer.android.com/reference/android/app/ActivityManager.html#getRunningAppProcesses%28%29">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
  }
}

这篇关于获取Android的活跃应用程序的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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