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 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  ww w  .  jav a2  s  .c om
        }
    }
    return isRunning;
}

From source file:Main.java

public static boolean isApplicationInStackHead(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return false;
        }//from   w w  w .  j av  a2  s.  c  o m
    }
    return true;
}

From source file:Main.java

/**
 * Gets cur process name./*from   www  .  j  a va2 s  . com*/
 *
 * @return the cur process name
 */
public static String getCurProcessName() {
    int pid = android.os.Process.myPid();
    ActivityManager mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
        if (appProcess.pid == pid) {
            return appProcess.processName;
        }
    }
    return null;
}

From source file:Main.java

public static boolean isApplicationBroughtToBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (tasks != null && !tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }//  w w  w.j  a va  2s  .  c o m
    }
    return false;
}

From source file:Main.java

public static boolean isApplicationInBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }/*w w  w  .j  a v a  2 s .  c om*/
    }
    return false;
}

From source file:Main.java

public static boolean isRunning(Context context, String packageName) {
    boolean running = false;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> procInfos = am.getRunningAppProcesses();
    if (procInfos != null) {
        for (RunningAppProcessInfo procInfo : procInfos) {
            if (procInfo.processName.equals(packageName)) {
                running = true;/*from   ww w . j a  v a2s . co  m*/
                break;
            }
        }
    }
    return running;
}

From source file:Main.java

public static boolean isAppRunning(Context context, String packageName) {
    if (packageName == null)
        return false;

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null)
        return false;
    for (RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.processName.equals(packageName)) {
            return true;
        }/*from w w  w. j a va  2 s . c  o  m*/
    }
    return false;
}

From source file:Main.java

public static String getTopPackageName(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName cn = activityManager.getRunningTasks(1).get(0).topActivity;
    return cn.getPackageName();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static boolean isAppStart(Context pContext, String packageName) {
    ActivityManager activityManager = (ActivityManager) pContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(100);
    for (RunningTaskInfo runningTaskInfo : tasksInfo) {
        if (packageName.equals(runningTaskInfo.topActivity.getPackageName())) {
            return true;
        }/*from  w w  w. ja v  a  2  s. com*/
    }
    return false;
}

From source file:Main.java

/**
 * whether the service is running./*from  ww  w.j av  a2  s.co  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;
}