Android O Replacement for getRunningServices

∥☆過路亽.° 提交于 2019-11-29 01:54:41

问题


In previous versions of Android, I used this method to find if a service from another app was up and running. It worked reliably for me:

ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);

However, with Android O this is now deprecated and will only return information about the calling apps services. I've looked into other solutions, but I don't want to ask the user for more permissions, (UsageStatsManager, NotificationManager, etc).

Is there an alternate solution for obtaining if a service from a different app is running or not in Android O?


回答1:


As per documentation:

As of O, this method is no longer available to third party applications.
For backwards compatibility, it will still return the caller's own services.

But may be this solution will help: How to check if a service is running on Android?



来源:https://stackoverflow.com/questions/45715905/android-o-replacement-for-getrunningservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!