Created
March 10, 2021 18:08
-
-
Save rommansabbir/b7feb40198da87c1671e92f13e7d5287 to your computer and use it in GitHub Desktop.
Check if a specific Service is running or not (Extension Function)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Context.isMyServiceRunning(serviceClass: Class<*>): Boolean { | |
val manager = this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | |
return manager.getRunningServices(Integer.MAX_VALUE) | |
.any { it.service.className == serviceClass.name } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment