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;
|
}
|
}
|