Example usage for android.app ActivityManager getRunningAppProcesses

List of usage examples for android.app ActivityManager getRunningAppProcesses

Introduction

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

Prototype

public List<RunningAppProcessInfo> getRunningAppProcesses() 

Source Link

Document

Returns a list of application processes that are running on the device.

Usage

From source file:Main.java

public static List<RunningAppProcessInfo> getRunningProcesses(Context ctx) {
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);

    return am.getRunningAppProcesses();
}

From source file:Main.java

static void destroySelfProcess(ActivityManager activityManger) {
    List<ActivityManager.RunningAppProcessInfo> appProcessList = activityManger.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo appProcessInfo : appProcessList) {
        int pid = appProcessInfo.pid;
        String processName = appProcessInfo.processName;
        if (-1 != processName.indexOf("com.wxlh.sptas")) {
            android.os.Process.killProcess(pid);
        }//from w w w . j  a va 2 s .  c  o  m
    }
}

From source file:Main.java

public static int getCountProcesses(Context mContext) {
    int iTemp = 0;
    ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    iTemp = manager.getRunningAppProcesses().size();
    return iTemp;
}

From source file:Main.java

public static int getRunningProcess(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> lists = am.getRunningAppProcesses();
    return lists.size();
}

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 ww .java  2s .com*/

    return false;
}

From source file:Main.java

public static boolean isRemoteService(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningAppProcessInfo process : manager.getRunningAppProcesses()) {
        if (VoiceClientSerivceProcessName.equals(process.processName)) {
            return Process.myPid() == process.pid;
        }//w w  w.j  av a 2s. com
    }
    return false;
}

From source file:Main.java

public static int getRunningProcessNumber(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();
    return runningAppProcesses.size();
}

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;//www.j av a2  s.c om
                break;
            }
        }
    }
    return running;
}

From source file:Main.java

public static boolean isBackGround() {
    ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
    for (RunningAppProcessInfo info : processInfos) {
        if (TextUtils.equals(info.processName, mContext.getPackageName())
                && info.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
            return true;
        }// w w  w  .  j  a  v a2s  .c  o m
    }
    return false;
}

From source file:Main.java

public static boolean isMainProcess(Context context) {
    ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));
    List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
    String mainProcessName = context.getPackageName();
    int myPid = android.os.Process.myPid();
    for (RunningAppProcessInfo info : processInfos) {
        if (info.pid == myPid && mainProcessName.equals(info.processName)) {
            return true;
        }//from  w  w  w  .ja v  a 2s  .c om
    }
    return false;
}