管灌系统巡查员智能手机App
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.dayu.pipirrapp.utils;
 
import android.app.ActivityManager;
import android.content.Context;
 
/**
 * ServiceUtils - 服务相关的公共方法
 *
 * @author zuoxiao
 * @version 1.0
 * @since 2024-12-12
 */
public class ServiceUtils {
 
    /**
     * 判断当前服务是否已经启动
     *
     * @param context
     * @param serviceClass
     * @return
     */
    public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }
}