So I'm trying to get the PID (Process ID) of a certain app that's running on my phone.
What I'm doing first is:
ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> pidsTask = activityManager.getRunningAppProcesses();
for(int i = 0; i < pidsTask.size(); i++){
nameList.append(pidsTask.get(i).processName + pidsTask.get(i).pid + "\n");
}
This get's the name + PID from 'every' app that's running currently.
Now, I want to get the PID of a certain app name "Com.ExampleName". Since the PID can/is Dynamic and can possibly change, I want it to be able to search the array for the name, get the position (i) and get the PID that belongs to that position (i).
How can I acomplish that?