本文实例讲述了Android编程获取手机后台运行服务的方法。分享给大家供大家参考,具体如下:
public static String getRunningServicesInfo(Context context) { StringBuffer serviceInfo = new StringBuffer(); final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> services = activityManager.getRunningServices(100); Iterator<RunningServiceInfo> l = services.iterator(); while (l.hasNext()) { RunningServiceInfo si = (RunningServiceInfo) l.next(); serviceInfo.append("npid: ").append(si.pid); serviceInfo.append("nnname:").append(si.service); serviceInfo.append("nnprocess: ").append(si.process); serviceInfo.append("nnservice: ").append(si.service); serviceInfo.append("nncrashCount: ").append(si.crashCount); serviceInfo.append("nnclientCount: ").append(si.clientCount); /*serviceInfo.append("nactiveSince: ").append(ToolHelper.formatData(si.activeSince)); serviceInfo.append("nlastActivityTime: ").append(ToolHelper.formatData(si.lastActivityTime));*/ serviceInfo.append("n============================"); serviceInfo.append("nnn"); } return serviceInfo.toString(); }
希望本文所述对大家Android程序设计有所帮助。