/** * @param context * @param classname * @return */ public static boolean isServiceRunning(final Context context, final String classname) { boolean running = false; try { final ActivityManager activitymanager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); final List<ActivityManager.RunningServiceInfo> runningserviceinfos = activitymanager.getRunningServices(Integer.MAX_VALUE); for (final ActivityManager.RunningServiceInfo runningserviceinfo : runningserviceinfos) { final String serviceclassname = runningserviceinfo.service.getClassName(); if (serviceclassname == null) { continue; } if (serviceclassname.equals(classname)) { running = true; break; } } } catch (Exception x) { DBG.m(x); } return running; }
private boolean isServiceRunning(String serviceName) { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) if (service.service.getClassName().equals(serviceName)) return true; return false; }