思路是这样的获取所有运行服务的名字,然后和自己服务的名字比对,
public static boolean isServiceAlive(Context context, String serviceName) { boolean flag = false; ActivityManager am = (ActivityManager) context .getSystemService(Activity.ACTIVITY_SERVICE); //返回100个服务 List<RunningServiceInfo> runningServices = am.getRunningServices(100); for (RunningServiceInfo runningServiceInfo : runningServices) { String allServiceName = runningServiceInfo.service.getClassName(); if(allServiceName.equals(serviceName)){ flag = true; } } return flag; }