得到android多有的正在執行的程式資訊
阿新 • • 發佈:2019-01-24
public List getRunningAppProcessInfo(){
Log.i("test", "getRunningAppProcessInfo()...");
List appProcessList = activity.getRunningAppProcesses();
Log.i("test", "getRunningAppProcessInfo()..."+appProcessList.size());
for(int i=0; i<appProcessList.size(); i++){
RunningAppProcessInfo appProcessInfo = (RunningAppProcessInfo) appProcessList.get(i);
//程序ID
int pid = appProcessInfo.pid;
//使用者ID,類似於Linux的許可權不同,ID也就不同, 比如root
int uid = appProcessInfo.uid;
//程序名,預設是包名或者由屬性android:process=""指定
String processName = appProcessInfo.processName;
//獲得該程序佔用的記憶體
int[] memPid = new int[]{ pid };
//此MemoryInfo位於android.os.Debug.MemoryInfo包中,用來統計程序的記憶體資訊
Debug.MemoryInfo[] memoryInfo = activity.getProcessMemoryInfo(memPid);
//獲取程序佔記憶體用資訊kb單位
int memSize = memoryInfo[0].dalvikPrivateDirty;
Log.i("test", "process name: " + processName + " pid: " + pid + " uid: " + uid + " memory size is -->" + memSize + "kb");
// textName.setText(processName);
temp +=uid + " " + pid + " " +processName +"\n";
tempId += uid+"\n";
//獲得每個程序裡執行的應用程式(包),即每個應用程式的包名
String[] packageList = appProcessInfo.pkgList;
for(String pkg : packageList){
Log.i("test", "package name " + pkg + " in process id is -->" + pid);
}
}
return appProcessList;
}
Log.i("test", "getRunningAppProcessInfo()...");
List appProcessList = activity.getRunningAppProcesses();
Log.i("test", "getRunningAppProcessInfo()..."+appProcessList.size());
for(int i=0; i<appProcessList.size(); i++){
RunningAppProcessInfo appProcessInfo = (RunningAppProcessInfo) appProcessList.get(i);
//程序ID
int pid = appProcessInfo.pid;
//使用者ID,類似於Linux的許可權不同,ID也就不同, 比如root
int uid = appProcessInfo.uid;
//程序名,預設是包名或者由屬性android:process=""指定
String processName = appProcessInfo.processName;
//獲得該程序佔用的記憶體
int[] memPid = new int[]{ pid };
//此MemoryInfo位於android.os.Debug.MemoryInfo包中,用來統計程序的記憶體資訊
Debug.MemoryInfo[] memoryInfo = activity.getProcessMemoryInfo(memPid);
//獲取程序佔記憶體用資訊kb單位
int memSize = memoryInfo[0].dalvikPrivateDirty;
Log.i("test", "process name: " + processName + " pid: " + pid + " uid: " + uid + " memory size is -->" + memSize + "kb");
// textName.setText(processName);
temp +=uid + " " + pid + " " +processName +"\n";
tempId += uid+"\n";
//獲得每個程序裡執行的應用程式(包),即每個應用程式的包名
String[] packageList = appProcessInfo.pkgList;
for(String pkg : packageList){
Log.i("test", "package name " + pkg + " in process id is -->" + pid);
}
}
return appProcessList;
}