package com.ydl.ydlcommon.utils

import android.app.ActivityManager
import android.content.Context

/**
 * Created by haorui on 2019/4/25.
 * Des:
 */
object AppUtils {
    fun isServiceRunning(context: Context, className: String): Boolean {
        if (className.isEmpty()) {
            return false
        }
        var isRunning: Boolean = false
        val activityManager: ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val serviceList: List<ActivityManager.RunningServiceInfo> = activityManager.getRunningServices(30)
        if (serviceList.isEmpty()) {
            return false
        }
        serviceList.forEach { item ->
            if (item.service.className == className) {
                isRunning = true
                return@forEach
            }
        }
        return isRunning
    }

}