【发布时间】:2017-01-11 17:24:06
【问题描述】:
我怀疑 ServiceManager 注册的服务,而不是 SystemServiceRegistry 注册的服务。
在SystemServiceRegistry 的cmets中
/**
* Manages all of the system services that can be returned by {@link Context#getSystemService}.
* Used by {@link ContextImpl}.
*/
也就是说System注册的服务可以从Context中得到他的引用。
关于ServiceManager,我怎样才能访问ServiceManager在一个应用程序中添加的服务,而该应用程序没有被SystemServiceRegistry注册?
【问题讨论】:
-
ServiceManager和SystemServiceRegistry都不是 Android SDK 的一部分。如注释所示,在Context上使用getSystemService()来检索系统服务。 -
是的,但是我要找的服务不是系统注册的,是ServiceManager添加的。上下文无法为我解决。
-
try/catch调用getSystemService("service_name")并检查调用是否将句柄返回给系统服务!= null... "未由系统注册并由系统添加的服务ServiceManager" AFAIK 添加服务与在ServiceManager中注册服务相同。 -
@Onik 我正在使用“库存”API。添加服务与在系统中注册服务不同,您可以在此问题的参考资料中查看。
-
@Andriel 好的。但是在不注册的情况下将服务添加到
ServiceManager的列表有什么意义呢?不是Context不能解决,你不能利用——系统不能操作。不管怎样,试试我建议的方法。
标签: android android-service system-services