判断Service是否已经启动
/** 查看服务是否开启*/
public static Boolean isServiceRunning(Context context, String serviceName) {
//获取服务方法 参数 必须用大写的Context!!!
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> infos = am.getRunningServices(100);
for (RunningServiceInfo info : infos) {
String className = info.service.getClassName();
if(serviceName.equals(className))
return true;
}
return false;
}