Get active Application name in Android

后端 未结 3 1317
一生所求
一生所求 2020-12-05 05:52

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

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 06:22

    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
      }
    }

提交回复
热议问题