获取正在运行的应用程

时间:2012-11-07 22:29:26

标签: android package

如何获得正在运行的应用程序包?我设法得到了名字,但找不到如何得到包。这是我的代码。

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
    List list = am.getRunningAppProcesses();
    Iterator iter = list.iterator();
    PackageManager pm = this.getPackageManager();
    while(iter.hasNext()) {
      ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(iter.next());
      try {
        CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
        Log.w("APPS", c.toString());
      }catch(Exception e) { }
    }catch(Exception e) { }
    }

由于

1 个答案:

答案 0 :(得分:0)

进程可以包含来自多个包的运行组件,请参阅RunningAppProcessInfo类中的字段pkgList