Search in sources :

Example 11 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project JustAndroid by chinaltz.

the class AbAppUtil method isServiceRunning.

/**
     * 用来判断服务是否运行.
     *
     * @param context   the context
     * @param className 判断的服务名字 "com.xxx.xx..XXXService"
     * @return true 在运行 false 不在运行
     */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 12 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project superCleanMaster by joyoyao.

the class AppUtil method isServiceRunning.

/**
     * 用来判断服务是否运行.
     *
     * @param context   the context
     * @param className 判断的服务名字 "com.xxx.xx..XXXService"
     * @return true 在运行 false 不在运行
     */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 13 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project mobile-android by photo.

the class UploaderServiceUtils method isServiceRunning.

/**
     * Check whether UploaderService is already running
     * 
     * @return
     */
public static boolean isServiceRunning(Class<? extends AbstractUploaderService> uploaderServiceClass) {
    final ActivityManager activityManager = (ActivityManager) CommonConfigurationUtils.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
    String serviceClassName = uploaderServiceClass.getName();
    for (RunningServiceInfo runningServiceInfo : services) {
        if (runningServiceInfo.service.getClassName().equals(serviceClassName)) {
            return true;
        }
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 14 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project AprilBeacon-Android-SDK by AprilBrother.

the class ServiceStatusUtils method isServiceRunning.

public static boolean isServiceRunning(Context context, String serviename) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> infos = am.getRunningServices(100);
    for (RunningServiceInfo info : infos) {
        String classname = info.service.getClassName();
        if (serviename.equals(classname)) {
            return true;
        }
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 15 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProcessStatsDetail method updateRunningServices.

private void updateRunningServices() {
    ActivityManager activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
    // Set all services as not running, then turn back on the ones we find.
    int N = mServiceMap.size();
    for (int i = 0; i < N; i++) {
        mServiceMap.valueAt(i).setCancellable(false);
    }
    N = runningServices.size();
    for (int i = 0; i < N; i++) {
        RunningServiceInfo runningService = runningServices.get(i);
        if (!runningService.started && runningService.clientLabel == 0) {
            continue;
        }
        if ((runningService.flags & RunningServiceInfo.FLAG_PERSISTENT_PROCESS) != 0) {
            continue;
        }
        final ComponentName service = runningService.service;
        CancellablePreference pref = mServiceMap.get(service);
        if (pref != null) {
            pref.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(CancellablePreference preference) {
                    stopService(service.getPackageName(), service.getClassName());
                }
            });
            pref.setCancellable(true);
        }
    }
}
Also used : CancellablePreference(com.android.settings.CancellablePreference) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager) OnCancelListener(com.android.settings.CancellablePreference.OnCancelListener)

Aggregations

RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)15 ActivityManager (android.app.ActivityManager)14 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 ComponentName (android.content.ComponentName)2 SuppressLint (android.annotation.SuppressLint)1 CancellablePreference (com.android.settings.CancellablePreference)1 OnCancelListener (com.android.settings.CancellablePreference.OnCancelListener)1 ProcessInfo (edu.berkeley.cs.amplab.carat.thrift.ProcessInfo)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1