命名运行应用程序而不是包名称

时间:2013-10-29 10:05:03

标签: java android activity-manager

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

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。我只需要cameraNova launcher

1 个答案:

答案 0 :(得分: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)");

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