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:org.sickstache.helper.BannerCache.java
private BannerCache(Context c) { c = c.getApplicationContext();/*w w w. ja v a 2s .c o m*/ this.cacheDir = new File(c.getExternalCacheDir(), cacheFolder); if (this.cacheDir.exists() == false) this.cacheDir.mkdirs(); int memClass = ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); // use half of the memory unless we have less then 32MB int cacheSize = memClass * 1024 * 1024 / 2; if (memClass < 32) cacheSize = memClass * 1024 * 1024 / 4; this.memCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:org.videolan.vlc.util.BitmapCache.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private BitmapCache() { // Get memory class of this device, exceeding this amount will throw an // OutOfMemory exception. final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext() .getSystemService(Context.ACTIVITY_SERVICE)); final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass(); // Use 1/5th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 5; Log.d(TAG, "LRUCache size sets to " + cacheSize); mMemCache = new LruCache<String, Bitmap>(cacheSize) { @Override/*w w w. j av a 2 s . co m*/ protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:Main.java
/** * Return <tt>true</tt> if the caller runs in a process dedicated to the Capptain service.<br/> * Return <tt>false</tt> otherwise, e.g. if it's the application process (even if the Capptain * service is running in it) or another process.<br/> * This method is useful when the <b>android:process</b> attribute has been set on the Capptain * service, if this method return <tt>true</tt>, application initialization must not be done in * that process. This method is used by {@link CapptainApplication}. * @param context the application context. * @return <tt>true</tt> if the caller is running in a process dedicated to the Capptain service, * <tt>false</tt> otherwise. * @see CapptainApplication/*from w w w . j av a 2 s . c o m*/ */ public static boolean isInDedicatedCapptainProcess(Context context) { /* Get our package info */ PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SERVICES); } catch (Exception e) { /* * NameNotFoundException (uninstalling?) or in some rare scenario an undocumented * "RuntimeException: Package manager has died.", probably caused by a system app process * crash. */ return false; } /* Get main process name */ String mainProcess = packageInfo.applicationInfo.processName; /* Get embedded Capptain process name */ String capptainProcess = null; if (packageInfo.services != null) for (ServiceInfo serviceInfo : packageInfo.services) if ("com.ubikod.capptain.android.service.CapptainService".equals(serviceInfo.name)) { capptainProcess = serviceInfo.processName; break; } /* If the embedded Capptain service runs on its own process */ if (capptainProcess != null && !capptainProcess.equals(mainProcess)) { /* The result is to check if the current process is the capptain process */ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningAppProcessInfo rapInfo : activityManager.getRunningAppProcesses()) if (rapInfo.pid == Process.myPid()) return rapInfo.processName.equals(capptainProcess); } /* Otherwise capptain is not running in a separate process (or not running at all) */ return false; }
From source file:fr.inria.ucn.collectors.AppDataUsageCollector.java
@Override public void run(Context c, long ts) { try {//from w ww. j a v a2 s . c o m // data used per app JSONArray parray = new JSONArray(); File f = new File(PROC_UID_STAT); if (f.exists() && f.isDirectory() && f.canRead()) { for (String dir : f.list()) { parray.put(getProcInfo(c, Integer.parseInt(dir))); } } else { ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo pinfo : am.getRunningAppProcesses()) { parray.put(getProcInfo(c, pinfo.uid)); } } // done Helpers.sendResultObj(c, "app_data_usage", ts, new JSONObject().put("process_list", parray)); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }
From source file:org.wahtod.wififixer.ui.MainActivity.java
private static void startwfService(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); boolean hasService = false; for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (WFMonitorService.class.getName().equals(service.service.getClassName())) { hasService = true;// ww w. j av a 2 s .c o m } } if (!hasService) context.startService(new Intent(context, WFMonitorService.class)); }
From source file:me.vijayjaybhay.galleryview.cache.MemoryImageCache.java
/** * Computes cache size/*from ww w .ja v a 2s .c o m*/ * @return maximum memory cache size */ private int getCacheSize() { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); int memClassBytes = am.getMemoryClass() * 1024 * 1024; return memClassBytes / 8; }
From source file:com.projecto.mapav2.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try {//from w ww .jav a 2 s .c o m setContentView(R.layout.activity_main); mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (mapa != null) { mapa.addMarker(new MarkerOptions().position(LOCATION_SURRREY).title("Find me here!")); mapa.setMyLocationEnabled(true); mapa.setTrafficEnabled(true); mapa.setMapType(GoogleMap.MAP_TYPE_HYBRID); } gps = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); GlEsVersion = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getDeviceConfigurationInfo().getGlEsVersion(); try { versionCode = context.getPackageManager().getPackageInfo("com.android.vending", 0).versionCode; versionCode2 = context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { pm = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData.getString("com.google.android.maps.v2.API_KEY"); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; Toast.makeText(MainActivity.this, "isGooglePlayServicesAvailable" + gps + "\n" + "GlEsVersion " + GlEsVersion + "\n" + "versionCode Vending" + versionCode + "\nversionCode GMS " + versionCode2 + "\n" + "getPackageManager " + pm + "\n" + "supportsEs2 " + supportsEs2 + "\n" + "getVersionFromPackageManager " + getVersionFromPackageManager(this) + "\n", Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); Log.d(INPUT_SERVICE, e.toString()); } int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); Log.e("Maps", "Result int value::" + result); switch (result) { case ConnectionResult.SUCCESS: Log.e("Maps", "RESULT:: SUCCESS"); break; case ConnectionResult.DEVELOPER_ERROR: Log.e("Maps", "RESULT:: DE"); break; case ConnectionResult.INTERNAL_ERROR: Log.e("Maps", "RESULT:: IE"); break; case ConnectionResult.INVALID_ACCOUNT: Log.e("Maps", "RESULT:: IA"); break; case ConnectionResult.NETWORK_ERROR: Log.e("Maps", "RESULT:: NE"); break; case ConnectionResult.RESOLUTION_REQUIRED: Log.e("Maps", "RESULT:: RR"); break; case ConnectionResult.SERVICE_DISABLED: Log.e("Maps", "RESULT:: SD"); break; case ConnectionResult.SERVICE_INVALID: Log.e("Maps", "RESULT:: SI"); break; case ConnectionResult.SERVICE_MISSING: Log.e("Maps", "RESULT:: SM"); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Log.e("Maps", "RESULT:: SVUR"); break; case ConnectionResult.SIGN_IN_REQUIRED: Log.e("Maps", "RESULT:: SIR"); break; default: break; } mapa.setMapType(GoogleMap.MAP_TYPE_NORMAL); mapa.setMyLocationEnabled(true); Log.e("Maps", "------EOC-------"); }
From source file:io.github.mkjung.ivi.gui.helpers.BitmapCache.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private BitmapCache() { // Get memory class of this device, exceeding this amount will throw an // OutOfMemory exception. final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext() .getSystemService(Context.ACTIVITY_SERVICE)); final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass(); // Use 1/5th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 5; Log.i(TAG, "LRUCache size set to " + cacheSize); mMemCache = new LruCache<String, CacheableBitmap>(cacheSize) { @Override/*from ww w. ja va 2s . c om*/ protected int sizeOf(String key, CacheableBitmap value) { return value.getSize(); } }; }
From source file:eu.nerdz.app.messenger.GcmIntentService.java
public boolean isActivityOpen() { ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); String name = activityManager.getRunningTasks(1).get(0).topActivity.getClassName(); return ConversationActivity.class.getCanonicalName().equalsIgnoreCase(name) || ConversationsListActivity.class.getCanonicalName().equalsIgnoreCase(name); }
From source file:fr.inria.ucn.collectors.SysStateCollector.java
/** * //w w w . ja v a 2 s .c o m * @param c * @param ts * @param change */ @SuppressLint("NewApi") public void run(Context c, long ts, boolean change) { try { JSONObject data = new JSONObject(); data.put("on_screen_state_change", change); // this collection run was triggered by screen state change data.put("hostname", Helpers.getSystemProperty("net.hostname", "unknown hostname")); data.put("current_timezone", Time.getCurrentTimezone()); // general memory state ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); JSONObject mem = new JSONObject(); mem.put("available", mi.availMem); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mem.put("total", mi.totalMem); } mem.put("is_low", mi.lowMemory); data.put("memory", mem); // screen state PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE); data.put("screen_on", pm.isScreenOn()); // battery state IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent battery = c.registerReceiver(null, ifilter); int level = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = battery.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float pct = (float) (100.0 * level) / scale; int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL); int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; JSONObject batt = new JSONObject(); batt.put("level", level); batt.put("scale", scale); batt.put("pct", pct); batt.put("is_charging", isCharging); batt.put("usb_charge", usbCharge); batt.put("ac_charge", acCharge); data.put("battery", batt); // some proc stats data.put("cpu", getCpuStat()); data.put("loadavg", getLoadStat()); data.put("uptime", getUptimeStat()); // audio state data.put("audio", getAudioState(c)); // done Helpers.sendResultObj(c, "system_state", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }