无需提供源代码即可访问 Android 服务
我正在创建一个我自己的应用程序将使用的 Android 服务,但我也希望它可供外部应用程序使用。
该服务是使用 AIDL 文件声明的。
我有两个独立的项目,一个用于服务,一个用于应用程序。 在 Eclipse 中,我引用应用程序项目中的服务项目来访问 AIDL 文件中生成的类,效果很好。
但现在,我想向其他应用程序授予该服务的访问权限,我该怎么做? 我应该分发 AIDL 文件吗?班级档案? 每个项目都必须将我的AIDL文件复制到他们的eclipse项目中?
如果我更改服务方法的签名怎么办?
谢谢
I am creating an Android service that my own app will use, but I also want it to be available to external apps.
The service is declared using AIDL files.
I have two separate projects, one for the service, one for the application.
In Eclipse I reference the service project in the application project to have access to the generated classes from the AIDL files, which works fine.
But now, I want to give access to the service to other apps, how do I do it?
Should I distribute the AIDL files? The class files?
Each project will have to copy my AIDL files into their eclipse project?
What if I change the signature of a method of the service?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望第三方访问您的服务,您必须为他们提供某种形式的界面。在这种情况下,这将是 AIDL。因此,您必须分发它,服务消费者必须使用它。他们很可能必须将其包含在他们的项目中。
如果您更改签名,他们将必须更新其代码。这是类似案例中的典型问题——欢迎来到俱乐部!您需要以某种形式对接口定义进行版本控制,然后阻止不兼容的客户端或提供一些转换层,以便它们使用旧接口访问您的新服务。
If you expect third parties to access your service you must provide some form of interface for them. This would be AIDL in this case. So you will have to distribute it and service consumers will have to use it. Most likely they will have to include it in their project.
If you change signature, they will have to update their code. This is a typical problem in similar cases - welcome to the club! You would need to version your interface definition in some form and then either block incompatible clients or provide some conversion layer so they access your new service using old interface.