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:util.Utils.java

public static boolean isMyServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.bidostar.pinan.version.VersionUpdateService".equals(service.service.getClassName())) {
            return true;
        }// w w  w.j a  va 2 s .c o  m
    }
    return false;
}

From source file:net.mceoin.cominghome.MainActivity.java

/**
 * Call using isMyServiceRunning(MyService.class)
 * http://stackoverflow.com/questions/600207/how-to-check-if-a-service-is-running-in-android
 */// www.ja v a 2  s  .  c o m
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:util.Utils.java

/**
 * ????./*w  w w .  j  a v a  2  s  .c  o  m*/
 *
 * @param mContext
 * @param className ???
 * @return true ? false ??
 */
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;
    }
    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:cz.muni.fi.japanesedictionary.main.MainActivity.java

/**
 * Determines whether ParserService is already running
 *
 * @param context Context of environment
 * @return true if ParserService is running else false
 *///from www.  ja  va 2  s. co m
public static boolean isMyServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
    List<RunningServiceInfo> runningServices = manager.getRunningServices(Integer.MAX_VALUE);
    if (runningServices == null) {
        return false;
    }
    for (RunningServiceInfo service : runningServices) {
        if (PARSER_SERVICE.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.googlecode.networklog.NetworkLog.java

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

    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (MyLog.enabled) {
            MyLog.d("Service: " + service.service.getClassName() + "; " + service.pid + "; "
                    + service.clientCount + "; " + service.foreground + "; " + service.process);
        }/*  w  ww. ja  v  a2s  . co  m*/

        if (serviceName.equals(service.service.getClassName())) {
            return true;
        }
    }

    return false;
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Checking a service is running or not// w  ww. j  ava2  s . c om
 *
 * @param context   Application context
 * @param myService Set your service class
 * @return
 */
public static boolean isServiceRunning(Context context, Class<?> myService) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (myService.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.farmerbb.secondscreen.util.U.java

public static boolean castScreenActive(Context context) {
    boolean castScreenActive = false;
    String castScreenService;/*from w  ww. ja v  a2s. c  o  m*/

    // On KitKat, we can look for the CastRemoteDisplayProviderService,
    // as it only runs when the "Cast screen" feature is active.
    // On Lollipop, this service is ALWAYS running, so we can't look for it.
    // However, if we are casting something while an external display is connected,
    // then we can reasonably assume that it most likely is casting the screen anyway.
    // So, look for the CastSocketMultiplexerLifeCycleService instead.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        castScreenService = "com.google.android.gms.cast.media.CastRemoteDisplayProviderService";
    else
        castScreenService = "com.google.android.gms.cast.service.CastSocketMultiplexerLifeCycleService";

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (service.service.getClassName().equals(castScreenService))
            castScreenActive = true;
    }

    return castScreenActive;
}

From source file:com.gm.goldencity.util.Utils.java

public static boolean isMyServiceRunning(Context ctx, String serviceClassName) {
    final ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    final List<ActivityManager.RunningServiceInfo> services = activityManager
            .getRunningServices(Integer.MAX_VALUE);

    for (ActivityManager.RunningServiceInfo runningServiceInfo : services) {
        if (runningServiceInfo.service.getClassName().equalsIgnoreCase(serviceClassName)) {
            return true;
        }//from www .  ja v  a  2  s.c  om
    }
    return false;
}

From source file:it.evilsocket.dsploit.core.System.java

public static boolean isServiceRunning(String name) {
    ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);

    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (name.equals(service.service.getClassName()))
            return true;
    }//from w  w  w .j  av a  2s  . c  o  m

    return false;
}

From source file:com.tcl.lzhang1.mymusic.MusicUtil.java

/**
 * check running service//from   w w w .j  a  v  a2s .c  o m
 * 
 * @param context
 * @param serviceName
 * @return
 */
public static boolean checkServiceIsRunning(Context context, String serviceName) {
    // Log.d(LOG_TAG, "will check service :" + serviceName);
    ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> mRunningServiceInfos = mActivityManager.getRunningServices(1000);
    for (RunningServiceInfo runningServiceInfo : mRunningServiceInfos) {
        if (null == runningServiceInfo) {
            continue;
        }

        if (serviceName.equals(runningServiceInfo.service.getClassName())) {
            // Log.d(LOG_TAG, "service[" + serviceName + "] is running");
            return true;
        }

    }

    return false;
}