Newer
Older
MonCalc / app / src / main / kotlin / jackall / moncalc / utils / ServiceUtil.kt
package jackall.moncalc.utils

import android.app.ActivityManager
import android.content.Context
import jackall.moncalc.service.MainService

/**
 * Created by matsumoto_k on 2017/11/03.
 */
class ServiceUtil {
    companion object {
        fun isMainServiceRunning(context: Context): Boolean {
            val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
            for (serviceInfo in manager.getRunningServices(Integer.MAX_VALUE)) {
                if (MainService::class.java.getName() == serviceInfo.service.className) {
                    return true
                }
            }
            return false
        }
    }
}