Skip to content

Instantly share code, notes, and snippets.

@rommansabbir
Created March 10, 2021 18:08
Show Gist options
  • Save rommansabbir/b7feb40198da87c1671e92f13e7d5287 to your computer and use it in GitHub Desktop.
Save rommansabbir/b7feb40198da87c1671e92f13e7d5287 to your computer and use it in GitHub Desktop.
Check if a specific Service is running or not (Extension Function)
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