在Android中获取系统正在运行的进程方法是getRunningAppProcesses()。我们首先通过ActivityManager _ActivityManager = (ActivityManager) this
.getSystemService(Context.ACTIVITY_SERVICE);来获取系统的全局状态,然后通过调用getRunningAppProcesses()方法就可以获得系统正在运行的进程。
代码
ActivityManager _ActivityManager = (ActivityManager) this
.getSystemService(Context.ACTIVITY_SERVICE);
List < RunningAppProcessInfo > list = _ActivityManager
.getRunningAppProcesses();
int i = list.size();
Log.i("tag", String.valueOf(i));
for (int j = 0; j < list .size(); j++) {
Log.i("tag", list.get(j).processName);
}
控制台输出: