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.google.android.gms.location.sample.locationupdatesforegroundservice.LocationUpdatesService.java

/**
 * Returns true if this is a foreground service.
 *
 * @param context The {@link Context}./*from w  w  w.j  ava 2  s  .  c  om*/
 */
public boolean serviceIsRunningInForeground(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (getClass().getName().equals(service.service.getClassName())) {
            if (service.foreground) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.luan.thermospy.android.activities.MainActivity.java

private boolean isMyServiceRunning(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   ww w. j a va2s  .c om*/
    }
    return false;
}

From source file:com.a3did.partner.recosample.MainActivity.java

private boolean isBackgroundRangingServiceRunning(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo runningService : am.getRunningServices(Integer.MAX_VALUE)) {
        if (RecoBackgroundRangingService.class.getName().equals(runningService.service.getClassName())) {
            return true;
        }//from w  w w . j  a  v  a  2s.  co m
    }
    return false;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static int getApplicationPid() {
    Context context = BaseApplication.getAppContext();
    String pkgName = getPackageName();

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> runningList = manager.getRunningAppProcesses();

    for (ActivityManager.RunningAppProcessInfo info : runningList) {
        if (TextUtils.equals(pkgName, info.processName)) {
            return info.pid;
        }/*  w w w  .j a v a 2 s. com*/
    }

    return 0;
}

From source file:fi.ohtu.mobilityprofile.ui.fragments.SettingsFragment.java

/**
 * Checks if PlaceRecorder is running./*w  ww .j  av a2s. c  om*/
 * @see PlaceRecorder
 * @return true/false
 */
private boolean isLocationServiceRunning() {
    ActivityManager manager = (ActivityManager) MainActivity.getContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (PlaceRecorder.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ??activity//from w  w w.j  a va 2  s .  c  om
 * 
 * @param context
 * @return
 */
@SuppressWarnings("deprecation")
public static ComponentName getTheProcessBaseActivity(final Context context) {
    ActivityManager activityManager = (ActivityManager) context.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    RunningTaskInfo task = activityManager.getRunningTasks(1).get(0);
    if (task.numActivities > 0) {
        LogUtil.d(TAG, "runningActivity topActivity=" + task.topActivity.getClassName());
        LogUtil.d(TAG, "runningActivity baseActivity=" + task.baseActivity.getClassName());
        return task.baseActivity;
    }
    return null;
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Check to see what's going on with the services, useful to check if the spell-checker service is active.
 * Probably should remove this, no longer necessary.
 * @return true if the Spellchecker service is running
 */// ww w.  j a va  2 s  .  co m
private boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        //Log.i("isService", service.service.getClassName()+",\n"+service.service.getPackageName());
        if (service.service.getClassName().contains("pell")) {
            //Log.i("isService", service.service.getClassName()+",\n"+service.service.getPackageName());
            if (service.service.getClassName().contains("ASpellChecker")) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.packetsender.android.MainActivity.java

public static boolean isMyServiceRunning(Context ctx) {
    ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.packetsender.android.PacketListenerService".equals(service.service.getClassName())) {
            return true;
        }//from w  w  w.  jav  a 2  s  . c o m
    }
    return false;
}

From source file:org.exobel.routerkeygen.ui.Preferences.java

private boolean isDictionaryServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("org.exobel.routerkeygen.DictionaryDownloadService".equals(service.service.getClassName())) {
            return true;
        }//  w  ww.j  a  v  a 2s .  c  o  m
    }
    return false;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static List<Integer> getApplicationPidList() {
    Context context = BaseApplication.getAppContext();
    String pkgName = getPackageName();

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> runningList = manager.getRunningAppProcesses();

    List<Integer> result = new ArrayList<>();
    for (ActivityManager.RunningAppProcessInfo info : runningList) {
        if (info.processName.contains(pkgName)) {
            result.add(info.pid);//from  w w w.j av  a  2  s .co m
        }
    }

    return result;
}