views:

20

answers:

2
PackageManager pm = this.getPackageManager();
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);

List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();

for(RunningAppProcessInfo process : runningAppProcesses) {
    try {
        ApplicationInfo ai = pm.getApplicationInfo(process.processName, PackageManager.GET_META_DATA);
        Log.d(TAG, applicationInfo.name + "");
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

process.processName returns a valid package name but applicationInfo.name is always null.

A: 

Try this

Log.d(TAG, ai.processName + "");

or this

Log.d(TAG, ai.packageName + "");
Marco Schmid
Works! but returns the package name, not the application name. Same as process.processName
Ragunath Jawahar
A: 

Used applicationInfo.loadLabel(pm) to find the Application name, but there should be a reason why applicationInfo.name didn't work.

Ragunath Jawahar