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

/**
 * Get Process Name by getRunningAppProcesses
 * <p/>/*from  w w  w .j a va 2s  .co m*/
 * It's been reported that sometimes, the list returned from
 * getRunningAppProcesses simply doesn't contain your own process
 * (especially when called from Application).
 * Use {@link #getProcessName(Context, int)} instead
 */
public static String getProcessName_PM(Context context, int pID) {
    String processName = "";
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = context.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                return info.processName;
            }
        } catch (Exception e) {
            Log.e(TAG, "getAppName: error", e);
        }
    }
    return processName;
}

From source file:Main.java

public static String getRunningAppNameByPID(Context context, int pid) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
        if (processInfo.pid == pid)
            return processInfo.processName;
    }//  w  w w  .  j av  a  2s  . c  o  m

    return null;
}

From source file:Main.java

public static boolean isProessRunning(Context context, String proessName) {
    boolean isRunning = false;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<ActivityManager.RunningAppProcessInfo> lists = am.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo info : lists) {
        if (info.processName.equals(proessName)) {
            isRunning = true;/*from w w w  .  j  ava 2s  .  c o m*/
            return isRunning;
        }
    }

    return isRunning;
}

From source file:Main.java

/**
 * @return null may be returned if the specified process not found
 *///from w  ww  .j  av a2  s . co  m
public static String getProcessName(Context cxt, int pid) {
    ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
    if (runningApps == null) {
        return null;
    }
    for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
        if (procInfo.pid == pid) {
            return procInfo.processName;
        }
    }
    return null;
}

From source file:Main.java

private static String getCurProcessName(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
        if (appProcess.pid == android.os.Process.myPid()) {
            return appProcess.processName;
        }/*  w w w .ja v  a2s . c  o  m*/
    }
    return "";
}

From source file:Main.java

static public int getSmartcardApiPid(Context context) {
    ActivityManager actvityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
    for (RunningAppProcessInfo procInfo : procInfos) {
        if (procInfo.processName.equals("org.simalliance.openmobileapi")
                || procInfo.processName.equals("org.simalliance.openmobileapi:remote"))
            return procInfo.pid;
    }/*ww  w. j  a v a  2 s. co m*/
    return 0;
}

From source file:Main.java

public static boolean isNamedProcess(Context context, String processName) {
    if (null == context) {
        return false;
    }/*from w  ww . j a v  a  2s  . co  m*/

    int pid = android.os.Process.myPid();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfoList = am.getRunningAppProcesses();
    if (null == processInfoList) {
        return true;
    }

    for (RunningAppProcessInfo info : processInfoList) {
        if (pid == info.pid && processName.equals(info.processName)) {
            return true;
        }
    }
    return false;
}

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;
        }//  www . j  a  v  a 2  s .co  m
    }
    return false;
}

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;
        }/* www . ja  v  a2 s . c o  m*/
    }
    return false;
}

From source file:Main.java

public static String getCurProcessName(Context context) {
    int pid = android.os.Process.myPid();
    ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
        if (appProcess.pid == pid) {
            return appProcess.processName;
        }//ww w .  j a  v  a  2 s  . c  om
    }
    return null;
}