ActivityManager activityManger = (ActivityManager) getSystemService(ACTIVITY_SERVICE);// 获取Activity管理器ListActivityManager.RunningServiceInfo serviceList = activityManger.getRunningServices(30);// 从窗口管理器中获取正在运行的Servicetv.setText(getServicesName(serviceList));setContentView(tv);}private boolean ServiceIsStart(ListActivityManager.RunningServiceInfo list, String className) {// 判断某个服务是否启动for (int i = 0; i list.size(); i++) {if (className.equals(list.get(i).service.getClassName()))return true;}return false;}private String getServicesName(ListActivityManager.RunningServiceInfo list) {// 获取所有服务的名称String res = "";for (int i = 0; i list.size(); i++) {res += list.get(i).service.getClassName() + "/n";}return res;}} 猜你喜欢