Android编程获取手机后台运行服务的方法
程序员文章站
2023-12-12 12:51:22
本文实例讲述了android编程获取手机后台运行服务的方法。分享给大家供大家参考,具体如下:
public static string getrunningser...
本文实例讲述了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程序设计有所帮助。