List of usage examples for android.content ComponentName getClassName
public @NonNull String getClassName()
From source file:Main.java
public static String getTopActName(Context ctx) { ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; String clsName = cn.getClassName(); return clsName; }
From source file:Main.java
public static String getTopActivityClassName(Context context) { try {// w w w . j a v a 2 s .c om ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; return cn.getClassName(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getTopActivityName(Context context) { try {//from w w w .ja v a2 s . 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; return topActivity.getClassName(); } } catch (Exception ex) { ex.printStackTrace(); } return ""; }
From source file:Main.java
public static boolean isRunningServer(String className, Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000); for (RunningServiceInfo runningServiceInfo : runningServices) { ComponentName service = runningServiceInfo.service; String className2 = service.getClassName(); if (className2.equals(className)) { return true; }/*from w w w .j av a 2 s.co m*/ } return false; }
From source file:Main.java
public static boolean isForeground(Context context, String className) { if (context == null || TextUtils.isEmpty(className)) { return false; }/* w w w . j av a2 s. c o m*/ ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1); if (list != null && list.size() > 0) { ComponentName cpn = list.get(0).topActivity; if (className.equals(cpn.getClassName())) { return true; } } return false; }
From source file:Main.java
public static String getTopActivityName(Context context) { String topActivityClassName = null; ActivityManager activityManager = (ActivityManager) (context .getSystemService(android.content.Context.ACTIVITY_SERVICE)); List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1); if (runningTaskInfos != null) { ComponentName f = runningTaskInfos.get(0).topActivity; topActivityClassName = f.getClassName(); }//from www.j a v a 2 s. co m return topActivityClassName; }
From source file:Main.java
private static String getTopActivityName(Context context) { String topActivityClassName = null; ActivityManager activityManager = (ActivityManager) (context .getSystemService(android.content.Context.ACTIVITY_SERVICE)); List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1); if (runningTaskInfos != null) { ComponentName f = runningTaskInfos.get(0).topActivity; topActivityClassName = f.getClassName(); }//w w w . j av a2s.co m return topActivityClassName; }
From source file:Main.java
public static boolean isServiceExisted(Context context, String className) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceList = activityManager .getRunningServices(Integer.MAX_VALUE); if (!(serviceList.size() > 0)) { return false; }/*from www. ja v a 2s.c o m*/ for (int i = 0; i < serviceList.size(); i++) { RunningServiceInfo serviceInfo = serviceList.get(i); ComponentName serviceName = serviceInfo.service; Log.d("services", serviceName.getClassName()); if (serviceName.getClassName().equals(className)) { return true; } } return false; }
From source file:Main.java
public static String getTopActivityName(Context context) { if (context == null) { return ""; }// www.j av a 2 s . c o m String topActivityClassName = null; try { 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; topActivityClassName = f.getClassName(); } } catch (Exception e) { } return topActivityClassName; }
From source file:Main.java
/** * Creates the configuration intent.//ww w .java 2 s.com * * @param component * the component * @param type * the type * * @return the intent */ public static Intent createConfigurationIntent(ComponentName component, String type) { return new Intent(CONFIGURE_ACTION).addCategory(component.getClassName()) .putExtra(SERVICE_KEY, component.flattenToString()).putExtra(TYPE_KEY, type); }