List of usage examples for android.content Context ACTIVITY_SERVICE
String ACTIVITY_SERVICE
To view the source code for android.content Context ACTIVITY_SERVICE.
Click Source Link
From source file:Main.java
public static boolean isServiceWork(Context mContext, String serviceName) { boolean isWork = false; ActivityManager myAM = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> myList = myAM.getRunningServices(140); if (myList.size() <= 0) { return false; }//w ww . j av a 2 s . co m for (int i = 0; i < myList.size(); i++) { String mName = myList.get(i).service.getClassName().toString(); if (mName.equals(serviceName)) { isWork = true; break; } } return isWork; }
From source file:Main.java
public static String getTopActivityName(Context context) { try {/* w w w .j a v a 2 s. c om*/ 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 String getRunningActivityName(Context context, String packageName) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> processInfos = activityManager.getRunningTasks(10); for (ActivityManager.RunningTaskInfo taskInfo : processInfos) { if (taskInfo.topActivity != null) { if (TextUtils.equals(packageName, taskInfo.topActivity.getPackageName())) { return taskInfo.topActivity.getClassName(); }//from ww w. j a v a 2 s. com } } return null; }
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 www . ja v a 2s. co m*/ } return false; }
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 a v a2s. c o m*/ } } return false; }
From source file:Main.java
public static long getAvailableRamInMegs(Context context) { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi);//from ww w. j ava2 s. c o m long availableMegs = mi.availMem / 1048576L; return availableMegs; }
From source file:Main.java
public static boolean isBackGround() { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses(); for (RunningAppProcessInfo info : processInfos) { if (TextUtils.equals(info.processName, mContext.getPackageName()) && info.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { return true; }//from w w w .j a v a 2 s .com } return false; }
From source file:Main.java
public static boolean isServiceRunning(Context mContext, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(30); if (!(serviceList.size() > 0)) { return false; }/* w w w . j ava 2 s . c om*/ for (int i = 0; i < serviceList.size(); i++) { if (serviceList.get(i).service.getClassName().equals(className) == true) { isRunning = true; break; } } return isRunning; }
From source file:Main.java
public static boolean isWorked(Context context, String serviceName) { ActivityManager myManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager .getRunningServices(Integer.MAX_VALUE); for (RunningServiceInfo runningServiceInfo : runningService) { if (runningServiceInfo.service.getClassName().equals(serviceName)) { return true; }/*from w ww .j av a2 s . c o m*/ } return false; }
From source file:Main.java
public static boolean isAppOnForeground(Context ctx) { ActivityManager activityManager = (ActivityManager) ctx.getApplicationContext()// .getSystemService(Context.ACTIVITY_SERVICE); String packageName = ctx.getApplicationContext().getPackageName(); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses == null) { return false; }//from www . j ava 2 s.c o m for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { return true; } } return false; }