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 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; }/* w ww. j a va 2 s . c o m*/ } return false; }
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; }//w w w.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
private static String getProcessName(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> infos = activityManager.getRunningAppProcesses(); int pid = Process.myPid(); RunningAppProcessInfo myInfo = null; for (RunningAppProcessInfo info : infos) { if (info.pid == pid) { myInfo = info;/* w ww .j a v a 2s . c om*/ break; } } return myInfo == null ? null : myInfo.processName; }
From source file:Main.java
public static String getProcessName(Context appContext) { String currentProcessName = null; int pid = android.os.Process.myPid(); ActivityManager manager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) { if (processInfo.pid == pid) { currentProcessName = processInfo.processName; break; }/*w w w . ja v a 2 s . c om*/ } return currentProcessName; }
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; }//from w w w . j ava 2s. c om } return false; }
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; }//from w w w. j a va 2 s .co m } return false; }
From source file:Main.java
public static boolean useMapsV2(final Context context) { if (Build.VERSION.SDK_INT >= 8) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; return supportsEs2; }// w w w . ja v a 2 s.com return false; }
From source file:Main.java
public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE); Iterator<RunningServiceInfo> l = servicesList.iterator(); while (l.hasNext()) { RunningServiceInfo si = (RunningServiceInfo) l.next(); if (className.equals(si.service.getClassName())) { isRunning = true;// w ww . j av a2s . c om } } return isRunning; }
From source file:Main.java
public static boolean isServiceRunning(Context ctx, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE); Iterator<RunningServiceInfo> l = servicesList.iterator(); while (l.hasNext()) { RunningServiceInfo si = l.next(); if (className.equals(si.service.getClassName())) { isRunning = true;//from w ww. ja va 2s. c o m } } return isRunning; }
From source file:Main.java
public static long availableMemory() { final Runtime runtime = Runtime.getRuntime(); final long used = runtime.totalMemory() - runtime.freeMemory(); final ActivityManager activityManager = (ActivityManager) sContext .getSystemService(Context.ACTIVITY_SERVICE); final long total = activityManager.getMemoryClass() * 1024 * 1024; return total - used; }