Search in sources :

Example 6 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project LshUtils by SenhLinsh.

the class AppUtils method isServiceRunning.

/**
     * 检查服务是否正在运行
     */
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
    //获取Activity管理器
    ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    //获取运行中服务
    List<RunningServiceInfo> services = manager.getRunningServices(1000);
    String serviceName = service.getName();
    for (RunningServiceInfo info : services) {
        //获取每一条运行中的服务的类名并判断
        String name = info.service.getClassName();
        if (TextUtils.equals(serviceName, name)) {
            return true;
        }
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 7 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project android_packages_apps_Torch by CyanogenMod.

the class TorchSwitch method torchServiceRunning.

private boolean torchServiceRunning(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> svcList = am.getRunningServices(100);
    for (RunningServiceInfo serviceInfo : svcList) {
        ComponentName serviceName = serviceInfo.service;
        if (serviceName.getClassName().endsWith(".TorchService") || serviceName.getClassName().endsWith(".RootTorchService"))
            return true;
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager)

Example 8 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project AndroidUtilCode by Blankj.

the class ServiceUtils method getAllRunningService.

/**
     * 获取所有运行的服务
     *
     * @param context 上下文
     * @return 服务名集合
     */
public static Set getAllRunningService(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF);
    Set<String> names = new HashSet<>();
    if (infos == null || infos.size() == 0)
        return null;
    for (RunningServiceInfo info : infos) {
        names.add(info.service.getClassName());
    }
    return names;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager) HashSet(java.util.HashSet)

Example 9 with RunningServiceInfo

use of android.app.ActivityManager.RunningServiceInfo in project AndroidUtilCode by Blankj.

the class ServiceUtils method isServiceRunning.

/**
     * 判断服务是否运行
     *
     * @param context   上下文
     * @param className 完整包名的服务类名
     * @return {@code true}: 是<br>{@code false}: 否
     */
public static boolean isServiceRunning(Context context, String className) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF);
    if (infos == null || infos.size() == 0)
        return false;
    for (RunningServiceInfo info : infos) {
        if (className.equals(info.service.getClassName()))
            return true;
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 10 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)

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