简体   繁体   English

我应该选择哪种应用程序间通信?

[英]Which kind of inter-application communication should I choose?

I need a push-logic message broadcast function in Android, to push data messages onto other applications that subscribe to the content. 我需要Android中的推送逻辑消息广播功能,以将数据消息推送到订阅该内容的其他应用程序上。 The subscribing applications should register with a filter setting and permissions, so that they only receive data they are interested in. This to ensure no unnecessary transmissions are made continuously since that would be a waste of resources. 订阅应用程序应向过滤器设置和权限进行注册,以便它们仅接收自己感兴趣的数据。这将确保不会连续进行不必要的传输,因为这将浪费资源。

Is there any ready-to-use mechanism in Android to accomplish this? Android中是否有任何现成的机制可以完成此任务?

I have looked at intent broadcasts, but it seems as if I pack data as a parcelable I don't have a filter function built in. I will always have to send all of the data in one parcelable and then unpack and extract the small part that I am interested in from there(?) 我已经查看了意图广播,但是好像我将数据打包为可打包的文件时没有内置过滤器功能。我将始终必须将所有数据发送到一个可打包的文件中,然后解压缩并提取一小部分我从那里感兴趣(?)

Then I looked at ContentProviders, but it seems they don't push messages onto a recipient, but instead are queried with a sql-like query-string for the content to be fetched. 然后,我查看了ContentProviders,但似乎它们没有将消息推送到收件人上,而是使用类似于sql的查询字符串查询要获取的内容。 Can a ContentProvider push messages onto a registered recipient using a query as a filter? ContentProvider可以使用查询作为过滤器将消息推送到注册的收件人上吗?

Maybe a complicated question to answer, but I give it a shot; 可能要回答一个复杂的问题,但我会试一试。 Which mechanism should I use, or do I have to write it myself? 我应该使用哪种机制,还是必须自己编写?

1 You can use intents to broadcast keys for filtering in apps then intrested apps can use content provider to fetch full data. 1您可以使用意图广播密钥以在应用程序中进行过滤,然后受关注的应用程序可以使用内容提供程序来获取完整数据。 2 Using of different intents for different datasets? 2对不同的数据集使用不同的意图?

Is there any ready-to-use mechanism in Android to accomplish this? Android中是否有任何现成的机制可以完成此任务?

That depends on what part of the problem you wish to consider being "ready-to-use". 这取决于您希望考虑将问题的哪一部分“准备使用”。 Pushing data to another app is handled via broadcast Intents . 通过广播Intents处理将数据推送到另一个应用程序。

I have looked at intent broadcasts, but it seems as if I pack data as a parcelable I don't have a filter function built in. I will always have to send all of the data in one parcelable and then unpack and extract the small part that I am interested in from there(?) 我已经查看了意图广播,但是好像我将数据打包为可打包的文件时没有内置过滤器功能。我将始终必须将所有数据发送到一个可打包的文件中,然后解压缩并提取一小部分我从那里感兴趣(?)

Your app would do the filtering, then send out broadcasts of the matches. 您的应用将进行过滤,然后发送匹配的广播。 This is a typical approach taken by broker-based "pub/sub" push models: the broker does the filtering, sending out only the relevant messages to subscribers over the communication channel. 这是基于代理的“发布/订阅”推送模型采用的一种典型方法:代理进行过滤,仅通过通信通道将相关消息发送给订户。 For example, GCM does not send every message destined for every device to every device and expect devices to do their own filtering -- the GCM servers do the filtering, then send the specific messages to the specific devices. 例如,GCM不会将发往每个设备的所有消息发送每个设备,并希望设备进行自己的过滤-GCM服务器会进行过滤,然后将特定的消息发送到特定的设备。

In some cases, you may be able to leverage IntentFilter capabilities to do the filtering for you. 在某些情况下,您可能可以利用IntentFilter功能为您进行过滤。 For example, suppose a message really represents a file. 例如,假设一条消息确实代表一个文件。 Files have MIME types. 文件具有MIME类型。 You could include the MIME type of the file in the Intent being broadcast, and the receivers could specify the MIME type(s) they are interested in via their filters. 您可以在正在广播的Intent中包括文件的MIME类型,接收者可以通过其过滤器指定他们感兴趣的MIME类型。 Receivers would only get messages from relevant broadcasts. 接收者只会从相关广播中获取消息。

However, for more arbitrary sorts of subscriptions (eg, "send me all messages that have certain values in certain JSON-encoded objects"), you would have to implement the filtering yourself. 但是,对于更多任意类型的订阅(例如,“向我发送在某些JSON编码的对象中具有某些值的所有消息”),则必须自己实现过滤。

Can a ContentProvider push messages onto a registered recipient using a query as a filter? ContentProvider可以使用查询作为过滤器将消息推送到注册的收件人上吗?

No, sorry. 不,对不起

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM