The problem now is that getRunningServices is now deprecated and doesn't return the running services anymore. Does anyone have experience with this issue on Android 8?Is there any official solution (or hack) available? I should also point out that the Service I want to look for is not in the same process/app as the code that is calling isMyServiceRunning() (that functionality is still provided for backward compatibility reasons)推荐答案 getRunningServices()此方法不再对第三方应用程序可用.没有获得运行服务的替代方法.getRunningServices() this method is no longer available to third party applications. there's no substitute method for getting the running service. https://developer.android.com/reference/android/app/ActivityManager.html#getRunningServices(int)如何检查服务是否在Android上运行?)我只是手动检查它,在服务运行时将布尔值设置为true,而在服务停止或销毁时将布尔值设置为false.我正在使用SharedPreferences保存布尔值.How to check if a service is running on Android?)I just check it manually , I put Boolean true when service is running and false when the service stopped or destroyed. I'm using SharedPreferences to save the Boolean value. Service.classService.classoverride fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { Log.d("service", "onStartCommand") setRunning(true)}private fun setRunning(running: Boolean) { val sessionManager = SessionManager(this) sessionManager.isRunning = running}override fun onDestroy() { setRunning(false) super.onDestroy()} SessionManager.classSessionManager.classclass SessionManager(var context: Context) { private val loginpreferences: SharedPreferences private val logineditor: SharedPreferences.Editor init { loginpreferences = context.getSharedPreferences(Pref_name, private_modde) logineditor = loginpreferences.edit() } var isRunning: Boolean get() = loginpreferences.getBoolean(SERVICES, false) set(value) { logineditor.putBoolean(SERVICES, value) logineditor.commit() } companion object { private val SERVICES = "service" }} 这篇关于如何检查服务是否在Android 8(API 26)上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!