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:library.artaris.cn.library.utils.SystemUtils.java
/** * ??//from ww w.ja v a 2 s . c o m * @param context * @return */ public static int getDeviceUsableMemory(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); return (int) (mi.availMem / (1024 * 1024)); }
From source file:com.gbaldera.tipaypal.TipaypalModule.java
private Boolean isPayPalServiceRunning() { ActivityManager manager = (ActivityManager) TiApplication.getAppCurrentActivity() .getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (PayPalService.class.getName().equals(service.service.getClassName())) { return true; }//from w ww. j ava 2 s.c om } return false; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.fragments.EventGeneratorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.traffic_fragment, container, false); if (D)//from w ww. ja v a2 s . c o m Log.d(TAG, TAG + ": onCreateView"); /* tiny hack */ ((CheckBox) rootView.findViewById(R.id.cbAcc)).setEnabled(false); ((CheckBox) rootView.findViewById(R.id.cbBP)).setEnabled(false); ((CheckBox) rootView.findViewById(R.id.cbHR)).setEnabled(false); ((CheckBox) rootView.findViewById(R.id.cbWeight)).setEnabled(false); ((EditText) rootView.findViewById(R.id.etAcc)).setEnabled(false); ((EditText) rootView.findViewById(R.id.etBP)).setEnabled(false); ((EditText) rootView.findViewById(R.id.etHR)).setEnabled(false); ((EditText) rootView.findViewById(R.id.etSimulationTime)).setEnabled(false); ((EditText) rootView.findViewById(R.id.etWeight)).setEnabled(false); isRunning = false; activityManager = (ActivityManager) getActivity() .getSystemService(android.content.Context.ACTIVITY_SERVICE); pid = android.os.Process.myPid(); Log.i(TAG, "PID: " + pid); /* set time zone */ df.setTimeZone(TimeZone.getTimeZone("gmt")); myManagementUtils = new EventUtils(ManagementEvent.getManagement(), "exampleSensor"); mReadingEventReceiver = new ReadingEventReceiver(); ((Button) rootView.findViewById(R.id.cbManual)).setOnClickListener(this); ((Button) rootView.findViewById(R.id.buttonStart)).setOnClickListener(this); return rootView; }
From source file:library.artaris.cn.library.utils.SystemUtils.java
/** * ????/*w w w . j a va 2 s.c o m*/ * @param context * @return */ public static int gc(Context context) { //long i = getDeviceUsableMemory(context); int count = 0; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> serviceList = am.getRunningServices(100); if (serviceList != null) for (RunningServiceInfo service : serviceList) { if (service.pid == android.os.Process.myPid()) continue; try { android.os.Process.killProcess(service.pid); count++; } catch (Exception e) { e.getStackTrace(); continue; } } List<RunningAppProcessInfo> processList = am.getRunningAppProcesses(); if (processList != null) for (RunningAppProcessInfo process : processList) { if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) { String[] pkgList = process.pkgList; for (String pkgName : pkgList) { try { am.killBackgroundProcesses(pkgName); count++; } catch (Exception e) { e.getStackTrace(); continue; } } } } return count; }
From source file:com.farmerbb.secondscreen.util.U.java
public static String uiRefreshCommand(Context context, boolean restartActivityManager) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses(); int processid = 0; if (restartActivityManager) { // Kill surfaceflinger if on a Jelly Bean device; run "am restart" if on KitKat or later if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { for (ActivityManager.RunningAppProcessInfo process : pids) { if (process.processName.equalsIgnoreCase("/system/bin/surfaceflinger")) processid = process.pid; }/*from w w w . j av a 2 s .co m*/ return "sleep 1 && kill " + Integer.toString(processid); } else return "sleep 1 && am restart"; } else { // Get SystemUI pid for (ActivityManager.RunningAppProcessInfo process : pids) { if (process.processName.equalsIgnoreCase("com.android.systemui")) processid = process.pid; } // Starting with 5.1.1 LMY48I, RunningAppProcessInfo no longer returns valid data, // which means we won't be able to use the "kill" command with the pid of SystemUI. // Thus, if the SystemUI pid gets returned as 0, we need to use the "pkill" command // instead, and hope that the user has that command available on their device. // Starting with 7.0, pkill doesn't work, so use "kill" and "pidof" instead. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) return "sleep 2 && kill `pidof com.android.systemui`"; else if (processid == 0) return "sleep 2 && pkill com.android.systemui"; else return "sleep 2 && kill " + Integer.toString(processid); } }
From source file:com.doomy.padlock.InfoFragment.java
/** * Gets random access memory size.//from w ww. j ava 2 s . c o m * * @return The RAM size. */ public String getRAMSize() { ActivityManager mActivityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mMemoryInfo = new ActivityManager.MemoryInfo(); mActivityManager.getMemoryInfo(mMemoryInfo); long mTotalMemory = mMemoryInfo.totalMem; return Formatter.formatFileSize(getActivity(), mTotalMemory); }
From source file:at.diamonddogs.util.Utils.java
/** * Checks if the current process is a foreground process (visible by the * user)/*from w w w .j av a 2s.co m*/ * * @param context a {@link Context} * @return <code>true</code> if the process is visible, <code>false</code> * otherwise */ public static boolean isInForground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE && appProcess.pid == Process.myPid()) { Log.i(TAG, "visible"); return true; } } Log.i(TAG, "Running in background"); return false; }
From source file:com.poloure.simplerss.FeedsActivity.java
private boolean isServiceRunning() { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (ServiceUpdate.class.getName().equals(service.service.getClassName())) { return true; }//from w w w .j av a2 s. c o m } return false; }
From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java
@SuppressWarnings("rawtypes") public SwitchLayout(Context context) { mContext = context;/* w w w . j a v a2s .c om*/ mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); mConfiguration = SwitchConfiguration.getInstance(mContext); mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mLoadedTasks = new ArrayList<TaskDescription>(); mRecentListAdapter = new RecentListAdapter(mContext, android.R.layout.simple_list_item_multiple_choice, mLoadedTasks); mFavoriteList = new ArrayList<String>(); mFavoriteListAdapter = new FavoriteListAdapter(mContext, android.R.layout.simple_list_item_multiple_choice, mFavoriteList); final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); am.getMemoryInfo(mMemInfo); String sClassName = "android.app.ActivityManager"; try { Class classToInvestigate = Class.forName(sClassName); Class[] classes = classToInvestigate.getDeclaredClasses(); for (int i = 0; i < classes.length; i++) { Class c = classes[i]; if (c.getName().equals("android.app.ActivityManager$MemoryInfo")) { String strNewFieldName = "secondaryServerThreshold"; Field field = c.getField(strNewFieldName); mSecServerMem = field.getLong(mMemInfo); break; } } } catch (ClassNotFoundException e) { } catch (NoSuchFieldException e) { } catch (Exception e) { } }
From source file:com.trellmor.berrytube.BerryTube.java
public static boolean isServiceRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (BerryTube.class.getName().equals(service.service.getClassName())) { return true; }//w ww . jav a2s. c o m } return false; }