I have a service which I believe to have running in the foreground, How do I check if my implementation is working?
This worked for me in the Coinverse app for crypto news.
It's is the most concise Kotlin solution. Thanks to Abbas Naqdi in this GitHub issue.
@Suppress("DEPRECATION") // Deprecated for third party Services.
fun Context.isServiceRunning(service: Class) =
(getSystemService(ACTIVITY_SERVICE) as ActivityManager)
.getRunningServices(Integer.MAX_VALUE)
.any { it.service.className == service.name }