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 String getProcessName(Context context) { int pid = android.os.Process.myPid(); ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) { if (appProcess.pid == pid) { return appProcess.processName; }/*from w w w . j a v a2 s . c o m*/ } return null; }
From source file:Main.java
/** *///w w w .j av a 2 s.c o m public static void clearEmptyTask(Context context) { ActivityManager activityManger = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> list = activityManger.getRunningAppProcesses(); if (list != null) for (int i = 0; i < list.size(); i++) { ActivityManager.RunningAppProcessInfo apinfo = list.get(i); String[] pkgList = apinfo.pkgList; if (apinfo.importance >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_EMPTY) {// >=300 android.os.Process.killProcess(apinfo.pid); for (int j = 0; j < pkgList.length; j++) { activityManger.killBackgroundProcesses(pkgList[j]); } } } }
From source file:Main.java
public static boolean isServiceRunning(Context context, Class serviceClass) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(serviceInfo.service.getClassName())) { return true; }//w w w . j ava2 s. c o m } return false; }
From source file:Main.java
public static boolean isAppRunningForeground(Context context) { ActivityManager var1 = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List list = var1.getRunningTasks(1); return context.getPackageName() .equalsIgnoreCase(((ActivityManager.RunningTaskInfo) list.get(0)).baseActivity.getPackageName()); }
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; }/*w ww .j a v a2s .co m*/ } return false; }
From source file:Main.java
public static String getAvailMemory(Context c) { ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi);/* w ww . j a va 2 s .c om*/ return Formatter.formatFileSize(c, mi.availMem); }
From source file:Main.java
public static void blockRecentApps(Activity activity) { ActivityManager activityManager = (ActivityManager) activity.getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.moveTaskToFront(activity.getTaskId(), 0); }
From source file:Main.java
public static boolean isTopApp(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> TaskList = am.getRunningTasks(2); if (TaskList == null || TaskList.isEmpty()) { return false; }/* w w w. j a v a 2 s .c om*/ RunningTaskInfo rti = TaskList.get(0); String tmp = rti.topActivity.getPackageName(); return tmp.equals(context.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 isMyServiceRunning(Context context, Class<?> clz) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (clz.getName().equals(service.service.getClassName())) { return true; }// w w w .ja v a 2 s .co m } return false; }