In free app *Device Internals for r1*, I get the running services this
way:
StringBuffer getRunningServices(ActivityManager am){
StringBuffer buf = new StringBuffer();
buf.append("\n\nRunning Services:");
List<ActivityManager.RunningServiceInfo> list = null;
try{
list = am.getRunningServices(100);
}catch(Throwable ex){
buf.append("\n "+ex);
return buf;
}
if(list.isEmpty()){
buf.append(" None listed.");
return buf;
}
int i = 1;
for(ActivityManager.RunningServiceInfo info: list){
buf.append("\n ["+i+"] pid {"+info.pid+"}:");
buf.append("\n foreground {"+info.foreground+"}");
buf.append("\n active since {"+info.activeSince+"} millis =
"+millisToSignHhMmSs(info.activeSince)+" "+HMS);
buf.append("\n last activity time {"+info.lastActivityTime+"}
millis = "+millisToSignHhMmSs(info.lastActivityTime)+" "+HMS);
buf.append("\n client count {"+info.clientCount+"}");
buf.append("\n crash count {"+info.crashCount+"}");
buf.append("\n service class {"+info.service.getClassName()
+"}");
buf.append("\n process {"+info.process+"}");
if(info.restarting==0){
buf.append("\n restarting at {"+info.restarting+"} zero means
not scheduled to restart");
}else{
buf.append("\n restarting at {"+info.restarting+"} millis =
"+millisToSignHhMmSs(info.restarting)+" "+HMS);
}
buf.append("\n started {"+info.started+"}");
//buf.append("\n toString {"+info.toString()+"}");
++i;
}
return buf;
}
And this will get you one process name if you know the Pid:
/** @return null when givenPid not found in list of 100 first
services. */
String getProcessNameFromPid(int givenPid){
ActivityManager am = (ActivityManager) getSystemService
(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> list =
am.getRunningServices(100);
for(ActivityManager.RunningServiceInfo info: list){
if(info.pid == givenPid){
return info.process;
}
}
return null;
}
cheers,
serge
On Feb 24, 4:23 am, sohail khan <[email protected]> wrote:
> Hi all,
>
> How do I get the Package Name if I am having the PID of the process. For
> example, if I want to output a list of currently
> running processes, I can get the PIDs but how do I get the names of the
> PIDs?
>
> Thanks.
> --
> sohail
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---