时间:2021-01-29 09:31:13 | 栏目:Android代码 | 点击:次
本文实例讲述了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("\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"); } return serviceInfo.toString(); }
希望本文所述对大家Android程序设计有所帮助。