Android Context Check isServiceRunning(Context ctx, String className)

Here you can find the source of isServiceRunning(Context ctx, String className)

Description

is Service Running

Declaration

public static boolean isServiceRunning(Context ctx, String className) 

Method Source Code

//package com.java2s;

import java.util.Iterator;
import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;

import android.content.Context;

public class Main {

    public static boolean isServiceRunning(Context ctx, String className) {
        boolean isRunning = false;
        ActivityManager activityManager = (ActivityManager) ctx
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningServiceInfo> servicesList = activityManager
                .getRunningServices(Integer.MAX_VALUE);
        Iterator<RunningServiceInfo> l = servicesList.iterator();
        while (l.hasNext()) {
            RunningServiceInfo si = (RunningServiceInfo) l.next();
            if (className.equals(si.service.getClassName())) {
                isRunning = true;//from w  w w  .ja  v a  2s . co  m
            }
        }
        return isRunning;
    }
}

Related

  1. isOnline(Context context)
  2. isOnline(Context context)
  3. isPermissionGranted(Context ctx)
  4. isSensAppInstalled(Context context)
  5. isServiceRunning(Context ctx, String className)
  6. isSystemApplication(Context context, String packageName)
  7. isTablet(Context ctx)
  8. isTablet(final Context context)
  9. isThemeInstalled(Context c, String theme)