Question

I need a push-logic message broadcast function in Android, to push data messages onto other applications that subscribe to the content. 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?

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. Can a ContentProvider push messages onto a registered recipient using a query as a filter?

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?

Was it helpful?

Solution

Is there any ready-to-use mechanism in Android to accomplish this?

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.

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.

In some cases, you may be able to leverage IntentFilter capabilities to do the filtering for you. For example, suppose a message really represents a file. Files have MIME types. 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. Receivers would only get messages from relevant broadcasts.

However, for more arbitrary sorts of subscriptions (e.g., "send me all messages that have certain values in certain JSON-encoded objects"), you would have to implement the filtering yourself.

Can a ContentProvider push messages onto a registered recipient using a query as a filter?

No, sorry.

OTHER TIPS

1 You can use intents to broadcast keys for filtering in apps then intrested apps can use content provider to fetch full data. 2 Using of different intents for different datasets?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top