Get active Application name in Android

2019-01-13 19:13发布

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 only.

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

3条回答
霸刀☆藐视天下
2楼-- · 2019-01-13 19:22

If you are getting the package name, you should be able to get additional information about the application using the PackageManager:

http://developer.android.com/reference/android/content/pm/PackageManager.html

There are direct methods for getting the application icon, ApplicationInfo and ActivityInfo objects. Off the top of my head I don't know which one would direct you to the readable name, but if its not directly accessible through one of the methods here, it should be accessible from the application resources (also accessible from this class).

查看更多
成全新的幸福
3楼-- · 2019-01-13 19:26

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

查看更多
老娘就宠你
4楼-- · 2019-01-13 19:49

I made some incorrect assumptions when making this post and now realize they were incorrect. - deleted

查看更多
登录 后发表回答