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
/** * Checks if the specified service is currently running or not. * @param context//from w w w . j a va 2 s.c o m * @param service * @param maxCheckCount * @return */ public static final boolean isServiceRunning(Context context, Class<? extends Service> service, int maxCheckCount) { if (context == null || service == null) { return false; } ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> list = manager.getRunningServices(maxCheckCount); for (RunningServiceInfo info : list) { if (service.getCanonicalName().equals(info.service.getClassName())) { return true; } } return false; }
From source file:Main.java
public static long[] getPSS(Context context, int pid) { long[] value = new long[3]; // Natvie Dalvik Total if (pid >= 0) { int[] pids = new int[1]; pids[0] = pid;/* w ww . ja v a 2 s. c o m*/ ActivityManager mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids); MemoryInfo pidMemoryInfo = memoryInfoArray[0]; value[0] = pidMemoryInfo.nativePss; value[1] = pidMemoryInfo.dalvikPss; value[2] = pidMemoryInfo.getTotalPss(); } else { value[0] = 0; value[1] = 0; value[2] = 0; } return value; }
From source file:Main.java
/** * Checks if an app or process with the specified package name is running * * @param context// www . ja v a2s.c om * @param packageName The package name of the app or process to check * @return <b>true</b> if running, <b>false</b> otherwise */ public static Boolean isRunning(Context context, String packageName) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> processInfo = activityManager.getRunningAppProcesses(); for (int i = 0; i < processInfo.size(); i++) { if (processInfo.get(i).processName.equals(packageName)) { return true; } } return false; }
From source file:org.anoopam.main.anoopamaudio.UtilFunctions.java
/** * Check if service is running or not//from w w w. j av a2 s . c om * @param serviceName * @param context * @return */ public static boolean isServiceRunning(String serviceName, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceName.equals(service.service.getClassName())) { return true; } } return false; }
From source file:tw.org.tsos.bsrs.MyVolley.java
static void init(Context context) { mClient = new DefaultHttpClient(); mRequestQueue = Volley.newRequestQueue(context/*,new HttpClientStack(mClient)*/); int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); // Use 1/8th of the available memory for this memory cache. int cacheSize = 1024 * 1024 * memClass / 8; mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(cacheSize)); }
From source file:Main.java
public static void killProcesses(Context context, int pid, String processName) { String cmd = "kill -9 " + pid; String Command = "am force-stop " + processName + "\n"; Process sh = null;// w ww . jav a2 s .c o m DataOutputStream os = null; try { sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); os.writeBytes(Command + "\n"); os.writeBytes(cmd + "\n"); os.writeBytes("exit\n"); os.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { sh.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // AbLogUtil.d(AbAppUtil.class, "#kill -9 "+pid); // L.i(processName); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); String packageName = null; try { if (processName.indexOf(":") == -1) { packageName = processName; } else { packageName = processName.split(":")[0]; } activityManager.killBackgroundProcesses(packageName); // Method forceStopPackage = activityManager.getClass().getDeclaredMethod("forceStopPackage", String.class); forceStopPackage.setAccessible(true); forceStopPackage.invoke(activityManager, packageName); } catch (Exception e) { e.printStackTrace(); } }
From source file:id.zelory.tanipedia.util.Utils.java
public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; }/*from w w w .j av a 2 s.co m*/ } return false; }
From source file:com.media.VideoLoadAsync.java
public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width) { mImageView = imageView;// w ww . j a v a2s . co m this.fragment = fragment; mWidth = width; mIsScrolling = isScrolling; final int memClass = ((ActivityManager) fragment.getActivity().getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); final int size = 1024 * 1024 * memClass / 8; // Handle orientation change. GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache(); mCache = c.mRetainedCache; if (mCache == null) { // The maximum bitmap pixels allowed in respective direction. // If exceeding, the cache will automatically scale the // bitmaps. /* * final int MAX_PIXELS_WIDTH = 100; final int MAX_PIXELS_HEIGHT = * 100; */ mCache = new GalleryCache(size, mWidth, mWidth); c.mRetainedCache = mCache; } }
From source file:Main.java
@SuppressWarnings("deprecation") public static boolean isServiceRunning(String activityClass, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningTaskInfo task : manager.getRunningTasks(Integer.MAX_VALUE)) { if (activityClass.equalsIgnoreCase(task.baseActivity.getClassName())) return true; }//from www . j a v a2 s .c o m return false; }
From source file:com.learnncode.mediachooser.async.VideoLoadAsync.java
public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width) { mImageView = imageView;//from w w w. j a va 2s. co m this.fragment = fragment; mIsScrolling = isScrolling; final int memClass = ((ActivityManager) fragment.getActivity().getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); final int size = 1024 * 1024 * memClass / 8; // Handle orientation change. GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache(); mCache = c.mRetainedCache; if (mCache == null) { // The maximum bitmap pixels allowed in respective direction. // If exceeding, the cache will automatically scale the // bitmaps. /* final int MAX_PIXELS_WIDTH = 100; final int MAX_PIXELS_HEIGHT = 100;*/ mCache = new GalleryCache(size, width, width); c.mRetainedCache = mCache; } }