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:Main.java

public static List<String> getProcessName(Context context, String packageName) {
    List<String> list = new ArrayList<String>();
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
        if (appProcess.processName.startsWith(packageName)) {
            list.add(appProcess.processName);
        }/*w  ww  . j av a2  s . c o  m*/
    }
    return list;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void killProgram(Context context, String packageName) {
    ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    try {/*from  w ww  . j ava2s.c  o m*/
        // 2.1 version
        mActivityManager.restartPackage(packageName);
    } catch (Exception e) {
        // 2.2 version
        mActivityManager.killBackgroundProcesses(packageName);
    }
}

From source file:Main.java

public static int getDeviceUsableMemory(Context cxt) {
    ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
    MemoryInfo mi = new MemoryInfo();
    am.getMemoryInfo(mi);/*from   w w  w  .  j  a  v a2 s  . c  om*/
    return (int) (mi.availMem / (1024 * 1024));
}

From source file:Main.java

public static boolean isMyServiceRunning(Context c, String name) {
    ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (name.equals(service.service.getClassName())) {
            return true;
        }/*from   w w w.  jav a  2  s.co  m*/
    }
    return false;
}

From source file:Main.java

public static boolean isMyAppRunning(Context context, String packageName) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    boolean run = false;
    for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
        if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            if (appProcess.processName.equals(packageName)) {
                run = true;//w  w w .j  a  va2 s.com
                break;
            }
        }
    }

    return run;
}

From source file:Main.java

public static String getTopActivity(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    @SuppressWarnings("deprecation")
    List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

    return runningTaskInfos == null ? "" : runningTaskInfos.get(0).topActivity.getClassName();
}

From source file:Main.java

@SuppressWarnings("unused")
public static String getOpenGLVersion(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ConfigurationInfo info = am.getDeviceConfigurationInfo();
    return info.getGlEsVersion();
}

From source file:Main.java

/**
 * @param ctx//from   w w  w . j  av  a 2  s .  c  o m
 * @param serviceClass
 * @return
 */
public static boolean isServiceRunning(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;
        }
    }
    return false;
}

From source file:Main.java

static public int getSmartcardApiPid(Context context) {
    ActivityManager actvityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
    for (RunningAppProcessInfo procInfo : procInfos) {
        if (procInfo.processName.equals("org.simalliance.openmobileapi")
                || procInfo.processName.equals("org.simalliance.openmobileapi:remote"))
            return procInfo.pid;
    }/*  ww  w.  j  a  v a2 s  .co m*/
    return 0;
}

From source file:Main.java

public static String getTopActivity(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

    if (runningTaskInfos != null)
        return runningTaskInfos.get(0).topActivity.getClassName();
    else/*from  ww w  .jav a 2s. c  om*/
        return "";
}