是否有 API 可以知道特定服务是否允许绑定?
我正在开发一个尝试与服务绑定的应用程序,但它失败了,因为它尝试绑定的服务未导出以供其他应用程序绑定。这让我想到是否有一种方法可以事先知道指定的服务类是否以编程方式接受绑定。
我知道通过检查 AndroidManifest.xml 的元素会建议导出= false还是true。但我想通过 API 调用或类似的东西来了解同样的情况。
I am working on a app which tries to bind with a service, but it fails to do so because service it is trying bind is not exported for other apps to bind. This made me think if there is a way to know before hand if a specified service class accepts binding or not programmatically.
I know by checking element of AndroidManifest.xml will suggest if exported = false or true. But I want to know the same by a API call or something like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,
ServiceRecord
包含此导出的信息,Android 没有提供这些信息获得访问权。最好的办法是在尝试绑定到服务时检查
SecurityException
。Sorry,
ServiceRecord
contains this exported' information, which Android has provided no way of getting access to.Your best bet is to check for a
SecurityException
when you try to bind to the Service.可能不是您想听到的,但实际上应该假设您不允许绑定到服务,除非应用程序 API 显式公开它。
Probably not what you want to hear, but should really just assum you're not allowed to bind to a service unless the apps API explicitly exposes it.