List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:Main.java
public static String getTopActivity2(Context ctx) { ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()); ComponentName componentInfo = taskInfo.get(0).topActivity; return componentInfo.getPackageName(); }
From source file:Main.java
public static boolean isBackgroundRunning(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; }/* www . ja v a 2 s . com*/ } return false; }
From source file:Main.java
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; }/*from w w w . ja va2s . c o m*/ } return false; }
From source file:Main.java
public static boolean isAppBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); @SuppressWarnings("deprecation") List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from w w w .j av a2 s.co m*/ } return false; }
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; }//from w ww . j a v a 2 s. co m } return false; }
From source file:Main.java
public static boolean isApplicationBackground(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; }//w ww .j av a 2 s. c o m } return false; }
From source file:Main.java
public static String getTopPackage(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); String ret = ""; try {//from w w w .j a va 2 s . c o m ComponentName cn = am.getRunningTasks(1).get(0).topActivity; ret = cn.getPackageName(); } catch (Exception e) { } return ret; }
From source file:Main.java
public static boolean isAppBackground(Context context) { if (context != null) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); @SuppressWarnings("deprecation") List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }// w w w . j av a 2s. c o m } } return false; }
From source file:Main.java
public static boolean isApplicationBroughtToBackground(final Context context) { try {/* ww w. ja va 2s. c o m*/ 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; } } } catch (Exception ex) { ex.printStackTrace(); } return false; }
From source file:Main.java
private static String toComponentName(ComponentName cn) { if (cn == null) return null; else/*w w w. ja va2 s. c om*/ return cn.getPackageName() + "/" + cn.getShortClassName(); }