Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:Main.java

public static boolean isInstalledAppRunning(Context context, String packageName) {
    boolean isAppRunning = false;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = am.getRunningTasks(100);
    for (RunningTaskInfo info : list) {
        if (info.topActivity.getPackageName().equals(packageName)
                && info.baseActivity.getPackageName().equals(packageName)) {
            isAppRunning = true;//from w  w  w  .j  a  v a  2 s  .c o  m
            break;
        }
    }
    return isAppRunning;
}

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;
    }/*  w  w w  . j av  a 2s.  co m*/

    return false;
}

From source file:Main.java

public static Set getAllRunningService(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF);
    Set<String> names = new HashSet<>();
    if (infos == null || infos.size() == 0)
        return null;
    for (RunningServiceInfo info : infos) {
        names.add(info.service.getClassName());
    }/*from   www . j  a v  a  2s . c o  m*/
    return names;
}

From source file:Main.java

public static boolean isRunningProcess(Context context, String packageName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> list = manager.getRunningAppProcesses();

    for (RunningAppProcessInfo procInfo : list) {
        if (procInfo.processName.equals(packageName))
            return true;
    }//from  w  w  w  .j  a va 2  s  .co  m

    return false;
}

From source file:Main.java

public static final boolean checkServiceRunning(final Context context, final String serviceName) {
    final ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (final RunningServiceInfo info : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (info.service.getClassName().equals(serviceName) && info.pid > 0) {
            return true;
        }//from  w w  w .  j av a  2 s  .com
    }
    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;
        }/*  w ww .  j a v  a 2  s. c  om*/
    }
    return false;
}

From source file:Main.java

public static final boolean checkServiceRunning(Context c, Class<? extends Service> cls) {
    ComponentName service = new ComponentName(c, cls);
    ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    if (am == null)
        throw new RuntimeException("Cannot check running services: ActivityManager is not available");
    for (ActivityManager.RunningServiceInfo runningService : am.getRunningServices(Integer.MAX_VALUE)) {
        if (runningService.service.equals(service))
            return true;
    }/*from   w w  w . j av a 2 s  . co  m*/
    return false;
}

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);
    for (RunningServiceInfo si : servicesList) {
        if (className.equals(si.service.getClassName())) {
            isRunning = true;//from  w  w  w. j a va 2s.  co  m
        }
    }
    return isRunning;
}

From source file:Main.java

/**
 * Check if service is running or not/*w  ww . j  a  va  2  s .  co  m*/
 *
 * @param serviceName
 * @param context
 * @return
 */
public static boolean isServiceRunning(String serviceName, Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceName.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean isServiceRunning(Context context, String serviceName) {
    ActivityManager manger = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> rs = manger.getRunningServices(50);

    for (RunningServiceInfo rsi : rs) {
        String className = rsi.service.getClassName();
        if (className.equals(serviceName)) {
            return true;
        }/*www  .  ja v a2  s . com*/
    }
    return false;
}