List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:Main.java
public static boolean isBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }// ww w. j a va2s . c o m } return false; }
From source file:Main.java
/** * Used to know if Apollo was sent into the background * /*www . ja v a 2s. c o m*/ * @param context The {@link Context} to use */ public static final boolean isApplicationSentToBackground(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final List<RunningTaskInfo> tasks = activityManager.getRunningTasks(1); if (!tasks.isEmpty()) { final ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; }
From source file:Main.java
public static boolean isApplicationToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*ww w. j a v a 2 s . c o m*/ } return false; }
From source file:Main.java
public static boolean isApplicationBroughtToBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = am.getRunningTasks(1); if (!taskInfo.isEmpty()) { ComponentName topActivity = taskInfo.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }// w w w .j a v a 2s .c om } 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
public static String getTopPackageName(Context context) { String topPackageName = null; try {//from www .j a va2 s.c om ActivityManager activityManager = (ActivityManager) (context .getSystemService(android.content.Context.ACTIVITY_SERVICE)); List<ActivityManager.RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1); if (runningTaskInfos != null) { ComponentName f = runningTaskInfos.get(0).topActivity; topPackageName = f.getPackageName(); } } catch (Exception e) { } return topPackageName; }
From source file:Main.java
/** * Checks if the application is in the background (i.e behind another application's Activity). * /* w w w . j a va 2s . c om*/ * @param context * @return true if another application is above this one. */ public static boolean isApplicationBroughtToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; }
From source file:Main.java
static void stopSelfService(ActivityManager activityManger) { List<ActivityManager.RunningServiceInfo> appProcessList = activityManger.getRunningServices(30); for (ActivityManager.RunningServiceInfo appProcessInfo : appProcessList) { if (-1 != appProcessInfo.process.indexOf("com.wxlh.sptas:tools")) { ComponentName service = appProcessInfo.service; activityManger.killBackgroundProcesses(service.getPackageName()); }/*from w ww. j a va 2 s .co m*/ } }
From source file:Main.java
public static final String getTopAppPackageName(final Context context) { String packageName = null;//from w w w. j a v a 2 s. c om ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> list = am.getRunningTasks(1); ComponentName comp = list.get(0).topActivity; if (null != comp) { packageName = comp.getPackageName(); } return packageName; }
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 ww . j a v a 2s . c o m*/ } return true; }