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.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java

@TargetApi(VERSION_CODES.KITKAT)
public static String getMemoryClass(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    String lowMem = "";

    if (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice()) {
        lowMem = ", low-mem device";
    }/*from   w  w  w  .ja v a 2s .  c  om*/
    return activityManager.getMemoryClass() + lowMem;
}

From source file:com.appassit.common.Utils.java

public static void clearBackMemory() {
    ActivityManager activityManager = (ActivityManager) SLAppication.getContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    int currentProcessId = android.os.Process.myPid();
    RunningAppProcessInfo runningAppProcessInfo = null;
    List<RunningAppProcessInfo> runningAppProcessInfos = activityManager.getRunningAppProcesses();
    if (runningAppProcessInfos != null) {
        for (int i = 0; i < runningAppProcessInfos.size(); ++i) {
            runningAppProcessInfo = runningAppProcessInfos.get(i);
            // RunningAppProcessInfo.IMPORTANCE_SERVICE
            // ?// www  .  j ava 2 s. c  o  m
            // RunningAppProcessInfo.IMPORTANCE_VISIBLE
            // ???,????
            if (runningAppProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE
                    && runningAppProcessInfo.pid != currentProcessId) {
                String[] pkgList = runningAppProcessInfo.pkgList;
                for (int j = 0; j < pkgList.length; ++j) {
                    activityManager.killBackgroundProcesses(pkgList[j]);
                    // count++;
                }
            }
        }
    }
}

From source file:by.zatta.pilight.MainActivity.java

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

From source file:com.flyingcrop.ScreenCaptureFragment.java

public boolean ServiceIsRunning() {
    ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.flyingcrop.Brush".equals(service.service.getClassName())) {
            return true;
        }//from  www .j  a v  a2s  .co  m
    }
    return false;
}

From source file:com.openarc.nirmal.nestle.LoginActivity.java

private boolean isRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (DataDownloadService.class.getName().equals(service.service.getClassName())) {
            return true;
        }//from w  w w  .  jav  a2s  .  c  om
    }
    return false;
}

From source file:org.pixmob.freemobile.netstat.MonitorService.java

private boolean isRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
        if (MonitorService.class.getName().equals(service.service.getClassName()))
            return true;
    return false;
}

From source file:com.hmatalonga.greenhub.ui.TaskListActivity.java

private double getAvailableMemory() {
    ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(info);

    return Math.round(info.availMem / 1048576.0 * 100.0) / 100.0;
}

From source file:grupo19.locmess19.Services.LocationUpdatesService.java

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;
            }//w w w.  j  a va  2s  .  co  m
        }
    }
    return false;
}

From source file:com.tcl.lzhang1.mymusic.MusicUtil.java

/**
 * check running service//from   w w  w . j  a  v a2s.  co  m
 * 
 * @param context
 * @param serviceName
 * @return
 */
public static boolean checkServiceIsRunning(Context context, String serviceName) {
    // Log.d(LOG_TAG, "will check service :" + serviceName);
    ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> mRunningServiceInfos = mActivityManager.getRunningServices(1000);
    for (RunningServiceInfo runningServiceInfo : mRunningServiceInfos) {
        if (null == runningServiceInfo) {
            continue;
        }

        if (serviceName.equals(runningServiceInfo.service.getClassName())) {
            // Log.d(LOG_TAG, "service[" + serviceName + "] is running");
            return true;
        }

    }

    return false;
}

From source file:org.restcomm.app.qoslib.Utils.QosAPI.java

static public boolean isRunning(Context context, String PackageName) {
    // Get the Activity Manager
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    // Get a list of running tasks, we are only interested in the last one,
    // the top most so we give a 1 as parameter so we only get the topmost.
    List<ActivityManager.RunningTaskInfo> rtasks = manager.getRunningTasks(10000);
    // Get the info we need for comparison.
    for (ActivityManager.RunningTaskInfo task : rtasks) {
        ComponentName c = task.baseActivity;
        if (c != null && c.toString().indexOf(PackageName) >= 0)
            return true;
    }//from ww  w  . jav  a2s.  c  o m

    //        List<ActivityManager.AppTask> tasks = manager.getAppTasks();
    //
    //        // Get the info we need for comparison.
    //        for (ActivityManager.AppTask task:tasks) {
    //            ComponentName c = task.getTaskInfo().origActivity;
    //            if (c == null && c.equals(watchActivity))
    //                return true;
    //        }

    // If not then our app is not on the foreground.
    return false;
}