Android上应用程序之间如何通信
我试图让一个应用程序作为服务在 android 上运行,其他应用程序将被分发,需要与其通信。
它已作为服务实现,并且当客户端应用程序打包在同一应用程序中时,运行客户端应用程序可以正常工作。
但是,遵循 http://developer.android.com/guide/developing/tools/aidl .html 我在客户端应用程序中遇到问题,特别是
“在 ServiceConnection.onServiceConnected() 的实现中,您将收到一个 IBinder 实例(称为服务)。调用 YourInterfaceName.Stub.asInterface( (IBinder)service) 将返回的参数转换为 YourInterface 类型。”
由于应用程序是单独分发的,我无法访问 YourInterfaceName 并将其复制到客户端应用程序绝对感觉像是“错误的方式”
如果有人可以提供指向文档/书籍/源代码的指针,这将非常有帮助,谢谢
(请原谅我名字中的讽刺,有点开玩笑)
I am trying to have an application that runs as a service on android, other apps will be distributed that need to communicate with it.
It has been implemented as a Service and running client apps work fine when they are packaged within the same app.
However following http://developer.android.com/guide/developing/tools/aidl.html I am having problems making this work for client applications, in particular the line
"In your implementation of ServiceConnection.onServiceConnected(), you will receive an IBinder instance (called service). Call YourInterfaceName.Stub.asInterface((IBinder)service) to cast the returned parameter to YourInterface type."
Since the applications are distributed separately I dont have access to YourInterfaceName and copying it across to the client app definitely feels like "the wrong way"
If anyone could provide a pointer to documentation / a book / source code that would be very helpful, thanks
(and forgive the irony in my name, was a bit of an in joke)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
《Pro Android 2》一书有一个关于 AIDL 的不错的例子......
The book "Pro Android 2" has a decent example on AIDL...
您必须将执行 Binder IPC 客户端的代码部分复制(或以其他方式包含或以类似功能重写)到客户端项目中。
You have to copy (or otherwise include, or rewrite with comparable functionality) the portion of the code that does the client end of the Binder IPC's into the client projects.
应用程序之间究竟需要什么通信?
如果是数据,那么你可以看一下 ContentProvider 。
您还可以通过
Intent.putExtra
共享信息。What exactly do the applications need to communicate to each other?
If it is data, then you can take a look at ContentProvider.
You could also share information through
Intent.putExtra
.