MY QUESTION: What could I use to retrieve the processName
or packageName
of a certain process given its PID
?
Since in my task manager I wanted to use the PID while utilizing the killBackgroundProcesses code to kill the processes. Problem is I need the packageName/processName to do that and it would be such a hassle to the user if I asked them to type in the processName rather than just typing its PID.
here's the image of my task manager:
This code is a simplified version of Yaqub's code. I use this as a static method in a Util
class:
public static String getAppNameByPID(Context context, int pid){
ActivityManager manager
= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for(RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()){
if(processInfo.pid == pid){
return processInfo.processName;
}
}
return "";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With