Android上应用程序之间如何通信

发布于 2024-10-05 19:25:34 字数 602 浏览 1 评论 0原文

我试图让一个应用程序作为服务在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑白记忆 2024-10-12 19:25:34

《Pro Android 2》一书有一个关于 AIDL 的不错的例子......

The book "Pro Android 2" has a decent example on AIDL...

自由范儿 2024-10-12 19:25:34

您必须将执行 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.

高速公鹿 2024-10-12 19:25:34

应用程序之间究竟需要什么通信?

如果是数据,那么你可以看一下 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文