Example usage for android.app ActivityManager getRunningServices

List of usage examples for android.app ActivityManager getRunningServices

Introduction

In this page you can find the example usage for android.app ActivityManager getRunningServices.

Prototype

@Deprecated
public List<RunningServiceInfo> getRunningServices(int maxNum) throws SecurityException 

Source Link

Document

Return a list of the services that are currently running.

Usage

From source file:Main.java

public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.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;// w  w w .j  av a 2 s. c  o  m
        }
    }
    return isRunning;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isServiceRun(Context context, Class<?> clazz) {
    boolean isRun = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    int size = serviceList.size();
    for (int i = 0; i < size; i++) {
        if (serviceList.get(i).service.getClassName().equals(clazz.getName())) {
            isRun = true;//from  w  w  w.  ja  v a  2 s .co  m
            break;
        }
    }
    return isRun;
}

From source file:Main.java

/**
 * whether the service is running.//from  ww w  .  j a  v  a  2 s. c o  m
 */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> servicesList = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    for (ActivityManager.RunningServiceInfo si : servicesList) {
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}

From source file:Main.java

public static boolean isServiceRunning(Context context, String className) {
    if (context == null) {
        return false;
    }/*from   w  w  w.  j a  v  a  2s.c  o m*/

    boolean isRunning = false;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ;
    List<ActivityManager.RunningServiceInfo> lists = am.getRunningServices(1000);
    for (ActivityManager.RunningServiceInfo info : lists) {
        if (info.service.getClassName().equals(className)
                && info.service.getPackageName().equals(context.getPackageName())) {
            isRunning = true;
            break;
        }
    }

    return isRunning;
}

From source file:Main.java

public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    if (serviceList == null || serviceList.isEmpty())
        return false;
    for (int i = 0; i < serviceList.size(); i++) {
        if (serviceList.get(i).service.getClassName().equals(className)
                && TextUtils.equals(serviceList.get(i).service.getPackageName(), context.getPackageName())) {
            isRunning = true;//w  w w  .j  a v a  2s .c om
            break;
        }
    }
    return isRunning;
}

From source file:Main.java

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();
        String serName = si.service.getClassName();
        Log.d("isServiceRunning", serName);
        if (className.equals(serName)) {
            isRunning = true;/* w  ww.jav a2s  .com*/
        }
    }
    return isRunning;
}

From source file:Main.java

public static boolean isServiceRunning(Context mContext, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(30);
    if (!(serviceList.size() > 0)) {
        return false;
    }// w  w  w  .j a  v  a2  s. c  o m
    for (int i = 0; i < serviceList.size(); i++) {
        if (serviceList.get(i).service.getClassName().equals(className) == true) {
            isRunning = true;
            break;
        }
    }
    return isRunning;
}

From source file:Main.java

/**
 * Checks if the specified service is currently running or not.
 * @param context//from   w w  w.j  a v  a2  s .  c  om
 * @param service
 * @param maxCheckCount
 * @return
 */
public static final boolean isServiceRunning(Context context, Class<? extends Service> service,
        int maxCheckCount) {
    if (context == null || service == null) {
        return false;
    }

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> list = manager.getRunningServices(maxCheckCount);
    for (RunningServiceInfo info : list) {
        if (service.getCanonicalName().equals(info.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean isServiceRunning(Context mContext, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    if (serviceList.size() == 0) {
        return false;
    }/*from  ww  w  . j  a  v a2 s.  c o m*/
    for (int i = 0; i < serviceList.size(); i++) {
        if (serviceList.get(i).service.getClassName().equals(className) == true) {
            isRunning = true;
            break;
        }
    }
    return isRunning;
}