一、獲取正在運行的進程列表:android
代碼app
ActivityManager mActivityManager = (ActivityManager) this .getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> list = mActivityManager .getRunningAppProcesses();
for (int j = 0; j < list.size(); j++) {
Log.i("tag", list.get(j).processName);
}this
二、經過Process.myPid()和 RunningAppProcessInfo來取得當前的進程名:spa
String getCurProcessName(Context context) {進程
int pid = android.os.Process.myPid();get
ActivityManager mActivityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE);it
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager .getRunningAppProcesses()) {List
if (appProcess.pid == pid) {vi
return appProcess.processName;process
}
}
return null;
}