用于getRunningServices的Android O替换 [英] Android O Replacement for getRunningServices

查看:821
本文介绍了用于getRunningServices的Android O替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以前的Android版本中,我使用此方法来查找其他应用程序的服务是否已启动并正在运行.它对我来说确实可靠:

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);

但是,现在不推荐使用Android O,它将仅返回有关调用应用程序服务的信息.我已经研究了其他解决方案,但是我不想让用户获得更多权限(UsageStatsManager,NotificationManager等).

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).

是否有替代解决方案可用于获取来自其他应用程序的服务是否正在Android O中运行?

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

推荐答案

此功能故意不可替代.从文档中还不太清楚,但是文档中的 :

It is intentional that there is no replacement for this function. It is not too clear from the documentation, but from the docs:

注意:此方法仅用于调试或实现服务管理类型的用户界面.

Note: this method is only intended for debugging or implementing service management type user interfaces.

基本上,使用该方法检查其他应用程序服务是意外的副作用,因此Google决定将其删除.可能出于隐私/安全目的,以避免应用嗅探"应用程序.用户设备上的其他应用/服务.

Basically, using the method to check other apps services was an unintended side-effect, so Google decided to remove it. Likely for privacy/security purposes to avoid apps "sniffing" other apps/services on the user's device.

您没有提到用例,但您希望避免向用户询问权限.但是,Google故意强迫开发人员明确要求他们所需的权限,您可以在

You didn't mention your use-case, but you want to avoid asking users for permissions. However, Google is intentionally forcing developers to explicitly request permissions they need, a philosophy which you can find explained here.

这篇关于用于getRunningServices的Android O替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆