Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:com.raspberry.library.util.AppUtils.java

/**
 * ????/*  ww  w.  j  a v  a  2 s  .c  o  m*/
 *
 * @param context
 * @return ??
 */
public static final String getProcessName(Context context) {
    String processName = null;

    // ActivityManager
    ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));

    while (true) {
        for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
            if (info.pid == android.os.Process.myPid()) {
                processName = info.processName;

                break;
            }
        }

        // go home
        if (!TextUtils.isEmpty(processName)) {
            return processName;
        }

        // take a rest and again
        try {
            Thread.sleep(100L);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.trovebox.android.app.bitmapfun.util.ImageCache.java

/**
 * Find and return an existing ImageCache stored in a {@link RetainFragment}
 * , if not found a new one is created with defaults and saved to a
 * {@link RetainFragment}./*from  w w w  .j  a v  a2 s  . c om*/
 * 
 * @param activity The calling {@link FragmentActivity}
 * @param uniqueName A unique name to append to the cache directory
 * @param diskCacheMaxItemSize max item size for the disk cache
 * @param diskCacheEnabled whether to enable first level disk cache
 * @param clearDiskCacheOnStart whether to clear disk cache on start
 * @param memCacheSizeRatio what part of memory will be available for cache
 *            (memory class/memCacheSizeRatio)
 * @return An existing retained ImageCache object or a new one if one did
 *         not exist.
 * @return
 */
public static ImageCache findOrCreateCache(final FragmentActivity activity, final String uniqueName,
        final int diskCacheMaxItemSize, boolean diskCacheEnabled, boolean clearDiskCacheOnStart,
        int memCacheSizeRatio) {
    ImageCacheParams params = new ImageCacheParams(uniqueName);
    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final int memClass = ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE))
            .getMemoryClass();

    // Use 1/8th of the available memory for this memory cache.
    params.memCacheSize = 1024 * 1024 * memClass / memCacheSizeRatio;
    params.clearDiskCacheOnStart = clearDiskCacheOnStart;
    params.diskCacheMaxItemSize = diskCacheMaxItemSize;
    params.diskCacheEnabled = diskCacheEnabled;
    CommonUtils.debug(TAG, "Calculated memory cache size: " + params.memCacheSize);

    return findOrCreateCache(activity, params);
}

From source file:com.odo.kcl.mobileminer.activities.MainActivity.java

private boolean miningActive() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (MinerService.class.getName().equals(service.service.getClassName())) {
            return true;
        }/* w  w w.j  a va  2s  .  c  o  m*/
    }
    return false;
}

From source file:com.remdo.app.MainActivity.java

private boolean isGEORunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (GeopositioningService.class.getName().equals(service.service.getClassName())) {
            return true;
        }// ww  w .j  a va  2s  .c  o m
    }
    return false;
}

From source file:com.serenegiant.testmediastore.MediaStorePhotoAdapter.java

public MediaStorePhotoAdapter(Context context, int id_layout) {
    super(context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mInflater = LayoutInflater.from(context);
    mCr = context.getContentResolver();/*from   w  w w.  j a  v a2s . c o  m*/
    mQueryHandler = new MyAsyncQueryHandler(mCr, this);
    // getMemoryClass return the available memory amounts for app as mega bytes(API >= 5)
    mMemClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    mLayoutId = id_layout;
    onContentChanged();
}

From source file:com.remdo.app.MainActivity.java

private boolean isALERTSRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (NotificationService.class.getName().equals(service.service.getClassName())) {
            return true;
        }//from  w ww. j a  v a2s.  co  m
    }
    return false;
}

From source file:org.failedprojects.anjaroot.PackagesFragment.java

public void killProcesses(List<String> pkgs) {
    boolean success = AnJaRoot.gainAccess();
    if (!success) {
        Log.e(LOGTAG, "Failed to gain access, something must be seriously broken...");
        return;/*from  ww w.  j  av a  2s.c  o  m*/
    }

    ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> runningapps = am.getRunningAppProcesses();
    for (RunningAppProcessInfo info : runningapps) {
        for (String pkgname : info.pkgList) {
            if (!pkgs.contains(pkgname)) {
                continue;
            }

            Log.v(LOGTAG,
                    String.format("Killing %s with pid %d as access has been revoked", pkgname, info.pid));
            Process.killProcess(info.pid);
        }
    }

    success = AnJaRoot.dropAccess();
    if (!success) {
        Log.e(LOGTAG, "Failed to drop access level");
    }
}

From source file:com.shadowmaps.example.GpsTestActivity.java

private boolean isShadowServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) 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  a v  a 2 s  .c  o  m*/
    }
    return false;
}

From source file:org.onepf.opfiab.opfiab_uitest.tests.ui.UnifiedFragmentHelperTest.java

private static void reopenActivity(Instrumentation instrumentation) throws InterruptedException {
    final Context context = instrumentation.getContext();
    @SuppressWarnings("deprecation")
    final Intent intent = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
            .getRecentTasks(2, 0).get(1).baseIntent;
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    instrumentation.getContext().startActivity(intent);
    Thread.sleep(WAIT_REOPEN_ACTIVITY);
}

From source file:com.zuzhili.bussiness.helper.CCPHelper.java

/**
 * Callback this method when SDK init success.
 * //w w  w  .  j a v  a 2 s.  c  om
 * Please note: you must write info that those remark start.
 * 
 * SDK init just once, but device can create more.
 * 
 * @see #onInitialized()
  * SDK?
 */
@Override
public void onInitialized() {
    try {
        mSession = Session.get(context);
        dbHelper = TaskApp.getInstance().getDbHelper();
        messageTable = dbHelper.getMessageTable();
        groupTable = dbHelper.getGroupInfoTable();
        // Activity?,??service
        am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        createDevice();
    } catch (Exception e) {
        e.printStackTrace();
        //throw new RuntimeException(e);
        onError(e);
    }
}