0

是否可能只有正在运行的应用程序的名称而不是包名称?我现在有这个代码:

ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> processes = am.getRunningAppProcesses();

        if (processes != null){
            for (int i=0; i<processes.size(); i++){
                RunningAppProcessInfo temp = processes.get(i);
                String pName = temp.processName;
                Log.d("Running process: ", pName);
            }
        }

但它返回包名称,如:com.android.camera. 我只需要camera或例如Nova launcher.

4

1 回答 1

1

尝试这个 :

final PackageManager pm = getApplicationContext().getPackageManager();
ApplicationInfo ai;
try {
   ai = pm.getApplicationInfo( this.getPackageName(), 0);
} 
   catch (final NameNotFoundException e) {
   ai = null;
}  
final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");

这将返回在其清单标记中定义的应用程序名称。

于 2013-10-29T10:08:36.313 回答