Android编程获取手机后台运行服务的方法
本文实例讲述了Android编程获取手机后台运行服务的方法。分享给大家供大家参考,具体如下:
publicstaticStringgetRunningServicesInfo(Contextcontext){ StringBufferserviceInfo=newStringBuffer(); finalActivityManageractivityManager=(ActivityManager)context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo>services=activityManager.getRunningServices(100); Iterator<RunningServiceInfo>l=services.iterator(); while(l.hasNext()){ RunningServiceInfosi=(RunningServiceInfo)l.next(); serviceInfo.append("\npid:").append(si.pid); serviceInfo.append("\n\nname:").append(si.service); serviceInfo.append("\n\nprocess:").append(si.process); serviceInfo.append("\n\nservice:").append(si.service); serviceInfo.append("\n\ncrashCount:").append(si.crashCount); serviceInfo.append("\n\nclientCount:").append(si.clientCount); /*serviceInfo.append("\nactiveSince:").append(ToolHelper.formatData(si.activeSince)); serviceInfo.append("\nlastActivityTime:").append(ToolHelper.formatData(si.lastActivityTime));*/ serviceInfo.append("\n============================"); serviceInfo.append("\n\n\n"); } returnserviceInfo.toString(); }
希望本文所述对大家Android程序设计有所帮助。