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

static void stopSelfService(ActivityManager activityManger) {
    List<ActivityManager.RunningServiceInfo> appProcessList = activityManger.getRunningServices(30);
    for (ActivityManager.RunningServiceInfo appProcessInfo : appProcessList) {
        if (-1 != appProcessInfo.process.indexOf("com.wxlh.sptas:tools")) {
            ComponentName service = appProcessInfo.service;
            activityManger.killBackgroundProcesses(service.getPackageName());
        }//from  ww w  .  ja va 2 s.c  o m
    }
}

From source file:Main.java

@SuppressWarnings("static-access")
public static boolean isServiceRunning(Context c, String serviceName) {
    ActivityManager manager = (ActivityManager) c.getSystemService(c.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceName.equals(service.service.getClassName())) {
            return true;
        }//from   w w  w  .j  a va2s. c o  m
    }
    return false;
}

From source file:Main.java

public static boolean isMyServiceRunning(Context context, Class<?> clz) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (clz.getName().equals(service.service.getClassName())) {
            return true;
        }/*from w  w  w .  j av  a  2s  .  c o  m*/
    }
    return false;
}

From source file:Main.java

public static boolean isMyServiceRunning(Context context, String serviceClassName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClassName.equalsIgnoreCase(service.service.getClassName())) {
            return true;
        }//from  w ww . j a  v a 2s.c om
    }
    return false;
}

From source file:Main.java

public static boolean isServiceRunning(Context context, Class serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*w ww .  j  av a  2  s.  c  om*/
    }
    return false;
}

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 servicesList = activityManager.getRunningServices(2147483647);
    Iterator l = servicesList.iterator();
    while (l.hasNext()) {
        ActivityManager.RunningServiceInfo si = (ActivityManager.RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;// w  ww.  j  a v a 2 s .  c o m
        }
    }
    return isRunning;
}

From source file:Main.java

/**
 * Checks if is service running./*from w ww . ja  v a 2  s .c  o m*/
 *
 * @param ctx the ctx
 * @param theService the the service
 * @return true, if is service running
 */
public static boolean isServiceRunning(Context ctx, Class theService) {
    ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (theService.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean isRunningService(Context context, String packageName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> list = manager.getRunningServices(1000);

    for (RunningServiceInfo procInfo : list) {
        if (procInfo.service.getClassName().equals(packageName))
            return true;
    }//from   w w w .j  av a  2 s .c om

    return false;
}

From source file:Main.java

public static boolean isServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        Log.d("InformatonUtils", "Service Name = " + service.service.getClassName());
        if ("com.safecell.TrackingService".equals(service.service.getClassName())) {
            return true;
        }/*ww  w .ja  v a  2 s . c o m*/
    }
    return false;
}

From source file:Main.java

public static boolean isServiceRunning(Class<? extends Service> serviceClass) {
    ActivityManager manager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*from  ww w  .  java  2s .co m*/
    }
    return false;
}