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:org.uguess.android.sysinfo.ProcessManager.java

void endAllExcept(String exception) {
    Activity ctx = getActivity();/* w  w w  .j  a v  a  2 s.c  o m*/
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);

    String self = ctx.getPackageName();

    ListView lstProcs = getListView();

    // skip the dummy info
    for (int i = 1, size = lstProcs.getCount(); i < size; i++) {
        ProcessItem rap = (ProcessItem) lstProcs.getItemAtPosition(i);

        String procName = rap.procInfo.processName;

        if (!ignoreList.contains(procName) && !self.equals(procName) && !rap.sys
                && !procName.equals(exception)) {
            endProcess(am, rap.procInfo.pkgList, self);
        }
    }

    if (!ignoreList.contains(self) && !self.equals(exception)) {
        Util.killSelf(handler, ctx, am, self);
    } else {
        handler.removeCallbacks(task);
        handler.post(task);
    }
}

From source file:com.gm.goldencity.util.Utils.java

private boolean isMyServiceRunning(Context ctx, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) ctx.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:cw.kop.autobackground.sources.SourceListFragment.java

private boolean isServiceRunning(final String className) {
    final ActivityManager manager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
    for (final ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (className.equals(service.service.getClassName())) {
            return true;
        }/*from  w w w  .  ja  v  a2s .  c  o m*/
    }
    return false;
}

From source file:com.xperia64.timidityae.TimidityActivity.java

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*from  ww w.  ja v  a 2  s  .  c  o m*/
    }
    return false;
}

From source file:org.torproject.android.OrbotMainActivity.java

private boolean isTorServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (TorService.class.getName().equals(service.service.getClassName())) {
            return true;
        }/*from   ww  w. ja v  a2s.  c o  m*/
    }
    return false;
}

From source file:pt.aptoide.backupapps.Aptoide.java

private void makeSureServiceDataIsRunning() {
    ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo runningService : activityManager.getRunningServices(Integer.MAX_VALUE)) {
        if (runningService.service.getClassName().equals(Constants.SERVICE_DATA_CLASS_NAME)) {
            this.serviceDataSeenRunning = true;
            break;
        }//w  w  w.  j  a v a  2s .co m
    }

    if (!serviceDataIsBound) {
        startService(new Intent(this, AptoideServiceData.class)); //TODO uncomment this to make service independent of Aptoide's lifecycle
        bindService(new Intent(this, AptoideServiceData.class), serviceDataConnection,
                Context.BIND_AUTO_CREATE);
    } else {
        handleIncomingIntent(getIntent());
    }
}

From source file:com.farmerbb.secondscreen.util.U.java

public static boolean castScreenActive(Context context) {
    boolean castScreenActive = false;
    String castScreenService;//from w ww  .ja v  a2  s .c  o m

    // On KitKat, we can look for the CastRemoteDisplayProviderService,
    // as it only runs when the "Cast screen" feature is active.
    // On Lollipop, this service is ALWAYS running, so we can't look for it.
    // However, if we are casting something while an external display is connected,
    // then we can reasonably assume that it most likely is casting the screen anyway.
    // So, look for the CastSocketMultiplexerLifeCycleService instead.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        castScreenService = "com.google.android.gms.cast.media.CastRemoteDisplayProviderService";
    else
        castScreenService = "com.google.android.gms.cast.service.CastSocketMultiplexerLifeCycleService";

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (service.service.getClassName().equals(castScreenService))
            castScreenActive = true;
    }

    return castScreenActive;
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private boolean isServiceRunning(String serviceClassName) {
    ActivityManager activityManager = (ActivityManager) getApplication()
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
    for (RunningServiceInfo runningServiceInfo : services) {
        if (runningServiceInfo.service.getClassName().equals(serviceClassName)) {
            return true;
        }/*from w w  w  .  j  a va 2 s .co  m*/
    }
    return false;
}

From source file:com.housekeeper.ar.healthhousekeeper.personalinfo.ModifyInfoActivity.java

public boolean isWorked() {
    ActivityManager myManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ArrayList<ActivityManager.RunningServiceInfo> runningService = (ArrayList<ActivityManager.RunningServiceInfo>) myManager
            .getRunningServices(30);/*  w  w w. j  a  v  a  2 s . co m*/
    for (int i = 0; i < runningService.size(); i++) {
        Log.i(TAG, "service name:  " + runningService.get(i).service.getClassName().toString());
        if (runningService.get(i).service.getClassName().toString()
                .equals("com.cn.ar.doctorclient.service.CheckUserService")) {
            Log.i(TAG, "check service is running");
            return true;
        }
    }
    Log.i(TAG, "check service is not running");
    return false;
}

From source file:com.findcab.activity.LocationOverlay.java

/**
 * //from   ww  w  . jav a2 s.com
 * 
 * @param context
 */
public void exitPro(Context context) {

    // ?Application
    String packName = context.getPackageName();
    ActivityManager activityMgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    activityMgr.restartPackage(packName);
    activityMgr.killBackgroundProcesses(packName);
    android.os.Process.killProcess(android.os.Process.myPid());
}