Example usage for android.app ActivityManager getRunningServices

List of usage examples for android.app ActivityManager getRunningServices

Introduction

In this page you can find the example usage for android.app ActivityManager getRunningServices.

Prototype

@Deprecated
public List<RunningServiceInfo> getRunningServices(int maxNum) throws SecurityException 

Source Link

Document

Return a list of the services that are currently running.

Usage

From source file:com.nextgis.maplibui.service.WalkEditService.java

public static boolean isServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
        if (WalkEditService.class.getName().equals(service.service.getClassName()))
            return true;

    return false;
}

From source file:com.nhn.android.archetype.base.AABaseApplicationOrg.java

public static void applicationAllKill() {
    final ActivityManager am = (ActivityManager) _internalInstance.getSystemService(Activity.ACTIVITY_SERVICE);
    // stop running service inside current process.
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    for (RunningServiceInfo service : serviceList) {
        if (service.pid == android.os.Process.myPid()) {
            Intent stop = new Intent();
            stop.setComponent(service.service);
            _internalInstance.stopService(stop);
        }//  w w  w.  j a va  2  s  . c om
    }

    // move current task to background.
    Intent launchHome = new Intent(Intent.ACTION_MAIN);
    launchHome.addCategory(Intent.CATEGORY_DEFAULT);
    launchHome.addCategory(Intent.CATEGORY_HOME);
    _internalInstance.startActivity(launchHome);

    // post delay runnable(waiting for home application launching)
    new Handler().postDelayed(new Runnable() {
        public void run() {
            am.killBackgroundProcesses(_internalInstance.getPackageName());
        }
    }, 2000);
}

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

/**
 * /*w  ww .j av a 2s . c o m*/
 * 
 * @param context
 */
public static void exitApp(final Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (context.getPackageName().equals(service.service.getPackageName())) {
            Intent stopIntent = new Intent();
            ComponentName serviceCMP = service.service;
            stopIntent.setComponent(serviceCMP);
            context.stopService(stopIntent);
            break;
        }
    }
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(0);
}

From source file:org.wahtod.wififixer.ui.MainActivity.java

private static void startwfService(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean hasService = false;
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (WFMonitorService.class.getName().equals(service.service.getClassName())) {
            hasService = true;//from w  w w.  ja v  a2s.co  m
        }
    }
    if (!hasService)
        context.startService(new Intent(context, WFMonitorService.class));
}

From source file:cn.apputest.ctria.service.UploadFailRecordService.java

public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceInfos = activityManager
            .getRunningServices(Constants.RETRIVE_SERVICE_COUNT);

    if (null == serviceInfos || serviceInfos.size() < 1) {
        return false;
    }/*from  www  . ja  va  2 s.  c  o m*/

    for (int i = 0; i < serviceInfos.size(); i++) {
        if (serviceInfos.get(i).service.getClassName().contains(className)) {
            isRunning = true;
            break;
        }
    }
    Log.i("ServiceUtil-AlarmManager", className + " isRunning =  " + isRunning);
    return isRunning;
}

From source file:com.seniordesign.autoresponder.Services.DrivingDetectionService.java

/** @return whether or not this service is running*/
public static boolean isRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (DrivingDetectionService.class.getName().equals(service.service.getClassName())) {
            return true;
        }//from  w w  w.  ja  v  a2s.c o  m
    }
    return false;
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ????//from w w  w  .  j  ava  2 s .  co  m
 * @param context
 * @return
 */
public static int gc(Context context) {
    //long i = getDeviceUsableMemory(context);
    int count = 0;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null)
        for (RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;
            } catch (Exception e) {
                e.getStackTrace();
                continue;
            }
        }

    List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null)
        for (RunningAppProcessInfo process : processList) {
            if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        e.getStackTrace();
                        continue;
                    }
                }
            }
        }
    return count;
}

From source file:com.nextgis.maplibui.service.TrackerService.java

public static boolean isTrackerServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (TrackerService.class.getName().equals(service.service.getClassName())) {
            return true;
        }//from  w w w .  j  a v  a  2s .c  om
    }

    return false;
}

From source file:com.trellmor.berrytube.BerryTube.java

public static boolean isServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (BerryTube.class.getName().equals(service.service.getClassName())) {
            return true;
        }/*  w  ww  .ja  v  a 2  s  .  c  o  m*/
    }
    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. j  av  a 2s.co m*/
    }
    return false;
}