0

Is possible have only the name of running application and not the package name? I have this code now:

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

But it returns the package name like: com.android.camera. I need only camera or for example Nova launcher.

David_D
  • 1,404
  • 4
  • 31
  • 65

1 Answers1

1

Try this :

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)");

This would return the application name as defined in tag of its manifest.

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69