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:com.nachtimwald.android.serviceexplorer.ServiceListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_servicelist, container, false); ListView lv = (ListView) view.findViewById(R.id.serviceList); List<Map<String, String>> serviceData = new ArrayList<>(); if (getArguments().getBoolean("allServices")) { for (PackageInfo packageInfo : getActivity().getPackageManager() .getInstalledPackages(PackageManager.GET_SERVICES)) { if (packageInfo.services == null) { continue; }// ww w. jav a 2s. c o m for (ServiceInfo serviceInfo : packageInfo.services) { Map<String, String> datum = new HashMap<>(); datum.put("name", serviceInfo.name); datum.put("package", serviceInfo.packageName); datum.put("search", serviceInfo.name.replace(".", " ").replace("$", " ")); serviceData.add(datum); } } } else { ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> runningServiceInfos = activityManager .getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo info : runningServiceInfos) { Map<String, String> datum = new HashMap<>(); datum.put("name", info.service.getClassName()); datum.put("package", info.service.getPackageName()); datum.put("search", info.service.getClassName().replace(".", " ").replace("$", " ")); serviceData.add(datum); } } mServicesAdapter = new SimpleAdapter(getActivity(), serviceData, android.R.layout.simple_list_item_2, new String[] { "name", "package", "search" }, new int[] { android.R.id.text1, android.R.id.text2, 0 }); lv.setAdapter(mServicesAdapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(getActivity(), DetailActivity.class); i.putExtra("name", ((HashMap<String, String>) parent.getItemAtPosition(position)).get("name")); i.putExtra("package", ((HashMap<String, String>) parent.getItemAtPosition(position)).get("package")); startActivity(i); } }); if (savedInstanceState != null) { lv.onRestoreInstanceState(savedInstanceState.getParcelable(STATE_LISTPOS)); } return view; }
From source file:org.tigase.mobile.utils.AvatarHelper.java
public static void initilize(Context context_) { if (avatarCache == null) { context = context_;//from w w w. ja v a 2s .c om density = context.getResources().getDisplayMetrics().density; defaultAvatarSize = Math.round(density * 50); // Get memory class of this device, exceeding this amount will throw // an // OutOfMemory exception. final int memClass = ((android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); // Use 1/8th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 8; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { avatarCache = new LruCache<BareJID, Bitmap>(cacheSize) { @TargetApi(12) @Override protected int sizeOf(BareJID key, Bitmap bitmap) { // The cache size will be measured in bytes rather than // number of items. Ignoring placeholder bitmap as well. return bitmap == mPlaceHolderBitmap ? 0 : bitmap.getByteCount(); } }; } else { // below SDK 12 there is no getByteCount method avatarCache = new LruCache<BareJID, Bitmap>(cacheSize) { @Override protected int sizeOf(BareJID key, Bitmap bitmap) { // The cache size will be measured in bytes rather than // number of items. Ignoring placeholder bitmap as well. return bitmap == mPlaceHolderBitmap ? 0 : (bitmap.getRowBytes() * bitmap.getHeight()); } }; } mPlaceHolderBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.user_avatar); } }
From source file:net.iamyellow.gcmjs.GCMIntentService.java
public static boolean isInForeground() { Context context = TiApplication.getInstance().getApplicationContext(); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); String packageName = context.getPackageName(); if (am.getRunningTasks(1).get(0).topActivity.getPackageName().equals(packageName)) { return true; }/*from ww w . java2 s . c o m*/ return false; }
From source file:com.github.opengarageapp.activity.MainActivity.java
public boolean isServiceRunning(String serviceClassName) { final ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE); for (RunningServiceInfo runningServiceInfo : services) { if (runningServiceInfo.service.getClassName().equals(serviceClassName)) { return true; }/* www . jav a2s . c o m*/ } return false; }
From source file:de.schildbach.wallet.util.CrashReporter.java
public static void appendDeviceInfo(final Appendable report, final Context context) throws IOException { final Resources res = context.getResources(); final android.content.res.Configuration config = res.getConfiguration(); final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); report.append("Device Model: " + Build.MODEL + "\n"); report.append("Android Version: " + Build.VERSION.RELEASE + "\n"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) report.append("Android security patch level: ").append(Build.VERSION.SECURITY_PATCH).append("\n"); report.append("ABIs: ").append(Joiner.on(", ").skipNulls().join(Strings.emptyToNull(Build.CPU_ABI), Strings.emptyToNull(Build.CPU_ABI2))).append("\n"); report.append("Board: " + Build.BOARD + "\n"); report.append("Brand: " + Build.BRAND + "\n"); report.append("Device: " + Build.DEVICE + "\n"); report.append("Display: " + Build.DISPLAY + "\n"); report.append("Finger Print: " + Build.FINGERPRINT + "\n"); report.append("Host: " + Build.HOST + "\n"); report.append("ID: " + Build.ID + "\n"); report.append("Product: " + Build.PRODUCT + "\n"); report.append("Tags: " + Build.TAGS + "\n"); report.append("Time: " + Build.TIME + "\n"); report.append("Type: " + Build.TYPE + "\n"); report.append("User: " + Build.USER + "\n"); report.append("Configuration: " + config + "\n"); report.append("Screen Layout: size " + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) + " long " + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_LONG_MASK) + "\n"); report.append("Display Metrics: " + res.getDisplayMetrics() + "\n"); report.append("Memory Class: " + activityManager.getMemoryClass() + "/" + activityManager.getLargeMemoryClass() + (ActivityManagerCompat.isLowRamDevice(activityManager) ? " (low RAM device)" : "") + "\n"); report.append("Storage Encryption Status: " + devicePolicyManager.getStorageEncryptionStatus() + "\n"); report.append("Bluetooth MAC: " + bluetoothMac() + "\n"); report.append("Runtime: ").append(System.getProperty("java.vm.name")).append(" ") .append(System.getProperty("java.vm.version")).append("\n"); }
From source file:ch.carteggio.ui.ConversationIconLoader.java
/** * Constructor./*from w w w.j av a 2s. c o m*/ * * @param context * A {@link Context} instance. * @param defaultBackgroundColor * The ARGB value to be used as background color for the fallback picture. {@code 0} to * use a dynamically calculated background color. */ public ConversationIconLoader(Context context, int defaultBackgroundColor) { Context appContext = context.getApplicationContext(); mContentResolver = appContext.getContentResolver(); mResources = appContext.getResources(); mHelper = new CarteggioProviderHelper(appContext); float scale = mResources.getDisplayMetrics().density; mPictureSizeInPx = (int) (PICTURE_SIZE * scale); mDefaultBackgroundColor = defaultBackgroundColor; ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); int memClass = activityManager.getMemoryClass(); // Use 1/16th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 16; mBitmapCache = new LruCache<Long, Bitmap>(cacheSize) { @Override protected int sizeOf(Long key, Bitmap bitmap) { // The cache size will be measured in bytes rather than number of items. return bitmap.getByteCount(); } }; }
From source file:org.solovyev.android.messenger.UnreadMessagesNotifier.java
@Nullable private ActivityManager.RunningTaskInfo getForegroundTask() { final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); // The first in the list of RunningTasks is always the foreground task. final List<ActivityManager.RunningTaskInfo> foregroundTasks = am.getRunningTasks(1); if (foregroundTasks != null && !foregroundTasks.isEmpty()) { return foregroundTasks.get(0); } else {//from w w w.jav a 2s. c o m return null; } }
From source file:com.manning.androidhacks.hack040.util.Utils.java
/** * Get the memory class of this device (approx. per-app memory limit) * //from w w w. j a v a 2 s. c om * @param context * @return */ public static int getMemoryClass(Context context) { return ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); }
From source file:com.manning.androidhacks.hack032.MainActivity.java
private boolean detectOpenGLES20() { ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); ConfigurationInfo info = am.getDeviceConfigurationInfo(); return (info.reqGlEsVersion >= 0x20000); }
From source file:com.weihuoya.bboo._G.java
public static boolean isServiceRunning(String className) { if (mRunningServices == null) { ActivityManager manager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE); mRunningServices = manager.getRunningServices(Integer.MAX_VALUE); }// ww w . j av a 2s . com for (ActivityManager.RunningServiceInfo info : mRunningServices) { if (info.service.getClassName().equals(className)) { return true; } } return false; }