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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…