List of usage examples for android.app ActivityManager getRunningAppProcesses
public List<RunningAppProcessInfo> getRunningAppProcesses()
From source file:com.activate.baidu.push.PushModule.java
private static boolean a(Context context) { boolean flag = true; try {//from www .j a va2 s . co m ActivityManager activitymanager = (ActivityManager) context.getSystemService("activity"); int i = Process.myPid(); Iterator iterator = activitymanager.getRunningAppProcesses().iterator(); do { if (!iterator.hasNext()) break; android.app.ActivityManager.RunningAppProcessInfo runningappprocessinfo = (android.app.ActivityManager.RunningAppProcessInfo) iterator .next(); if (runningappprocessinfo.pid == i) { String s = c(context); if (runningappprocessinfo.processName.equalsIgnoreCase(s)) { boolean flag1 = b(context.getApplicationContext()); if (!flag1) Process.killProcess(i); } } } while (true); } catch (Exception exception) { flag = false; exception.printStackTrace(); } return flag; }
From source file:org.restcomm.app.utillib.Utils.Global.java
public static int getAppImportance(String packageName, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Service.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo info : runningProcesses) { String process = info.processName; if (process.equals(packageName)) { if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { return 1; //foreground } else if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { return 2; //background } else if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { return 3; //visible - actively visible to the user, but not in the immediate foreground } else if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) { return 4; //visible - actively visible to the user, but not in the immediate foreground } else if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE) { return 5; //visible - actively visible to the user, but not in the immediate foreground }//from w w w. j a v a 2 s .c om } } return 0; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ???<br/>// w ww.j a v a 2 s . co m * id??????+?? * * @param context * @param pid * @return */ public static String getProcessNameByPid(Context context, final int pid) { String processName = null; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses != null) { for (RunningAppProcessInfo appProcess : appProcesses) { if (pid == appProcess.pid) { processName = appProcess.processName; break; } } } LogUtil.d(TAG, "getProcessNameByPid,pid=", pid, ",processName=", processName); return processName; }
From source file:cn.bingoogolapple.scaffolding.util.AppManager.java
public static boolean isInOtherProcess(Context context) { String processName = null;//from ww w . j a va 2 s. c o m ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); Iterator iterator = am.getRunningAppProcesses().iterator(); while (iterator.hasNext()) { ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (iterator.next()); try { if (info.pid == android.os.Process.myPid()) { processName = info.processName; } } catch (Exception e) { Log.d(AppManager.class.getSimpleName(), "Error>> :" + e.toString()); } } return processName == null || !processName.equalsIgnoreCase(context.getPackageName()); }
From source file:com.raspberry.library.util.AppUtils.java
/** * ????/* w w w . j a v a 2 s .com*/ * * @param context * @return ?? */ public static final String getProcessName(Context context) { String processName = null; // ActivityManager ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)); while (true) { for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) { if (info.pid == android.os.Process.myPid()) { processName = info.processName; break; } } // go home if (!TextUtils.isEmpty(processName)) { return processName; } // take a rest and again try { Thread.sleep(100L); } catch (InterruptedException ex) { ex.printStackTrace(); } } }
From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java
/** * Checks if the app is in foreground//www . ja va 2 s . co m * @param context from which call is made * @return true if is in foreground, false - otherwise */ public static boolean checkForeground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { Log.i("Foreground App", appProcess.processName); if (context.getPackageName().equalsIgnoreCase(appProcess.processName)) { Log.i(TAG, "foreground true:" + appProcess.processName); return true; } else { return false; } } } return false; }
From source file:at.diamonddogs.util.Utils.java
/** * Checks if the current process is a foreground process (visible by the * user)/*from w w w .ja v a2 s. co m*/ * * @param context a {@link Context} * @return <code>true</code> if the process is visible, <code>false</code> * otherwise */ public static boolean isInForground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE && appProcess.pid == Process.myPid()) { Log.i(TAG, "visible"); return true; } } Log.i(TAG, "Running in background"); return false; }
From source file:library.artaris.cn.library.utils.SystemUtils.java
/** * ??????/*ww w. ja v a2s . co m*/ * @param context * @return */ public static boolean isBackground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName())) { return appProcess.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND; } } return false; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ???????//from ww w .java 2 s. c o m * * @param context * @return */ public static boolean checkTheProcess(final Context context, String endProcessName) { ActivityManager activityManager = (ActivityManager) context.getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); int myPid = android.os.Process.myPid(); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses != null) { for (RunningAppProcessInfo appProcess : appProcesses) { if (myPid == appProcess.pid) { LogUtil.d(TAG, "process.pid appProcess.processName=" + appProcess.processName + ", endProcessName=" + endProcessName); if (appProcess.processName.endsWith(endProcessName)) { return true; } break; } } } return false; }
From source file:at.diamonddogs.util.Utils.java
/** * Same as {@link Utils#commitCarefulSuicide(Context)} but threaded (non * blocking)/*from w w w.j a va 2 s. c o m*/ * * @param context */ public static final void commitCarefulSuicideThreaded(final Context context) { new Thread(new Runnable() { @Override public void run() { ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses == null) { return; } Log.d(TAG, "app counter: " + appProcesses.size()); final String packageName = context.getPackageName(); for (RunningAppProcessInfo appProcess : appProcesses) { Log.d(TAG, "process: " + appProcess.processName); if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) { Log.d(TAG, "isINF: " + true); return; } } Log.d(TAG, "isINF: " + false); commitSuicide(); } }).start(); }