Android编程获取手机后台运行服务的方法
内容摘要
本文实例讲述了Android编程获取手机后台运行服务的方法。分享给大家供大家参考,具体如下:
public static String getRunningServicesInfo(Context context) {
StringBuffe
public static String getRunningServicesInfo(Context context) {
StringBuffe
文章正文
本文实例讲述了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程序设计有所帮助。
代码注释