TomTaila
TomTaila

Reputation: 1694

How can I receive pending messages using google nearby API?

I would like to be able to send a message from one user to another using google nearby API. However, according to their guidelines having the device in a subscribe/publish state uses 2.5-3.5 times more battery than usual. Therefore they recommend that you only subscribe/publish once your activity enters the foreground. But that means, unless two devices have the app on screen at the SAME TIME, they will not be able to send/receive messages to one another. I would like for user A to enter the foreground, send a message, and when user B enters the foreground, for them to see that message.

The ideal scenario would be to perform something like firechat (https://play.google.com/store/apps/details?id=com.opengarden.firechat&hl=en). Where you send/receive messages real time. Are they just leaving subscribing/publishing in the background all the time regardless of battery consumption?

I would like to add that my ultimate goal is to be able to make a frictionless (no pairing necessary) chat between people nearby one another (capable of reaching 30m distance). So if there is a better way to do this in general that would be interesting to hear.

Upvotes: 4

Views: 462

Answers (1)

EyesClear
EyesClear

Reputation: 28417

I would like for user A to enter the foreground, send a message, and when user B enters the foreground, for them to see that message.

That's exactly how it works. Each message has a TTL (time to live) attribute which is set to 300 seconds by default (see: Strategy). As long as the message is live (meaning TTL is still valid and user A didn't unpublish it), user B will be able to find it soon after he subscribes.

The whole concept of messaging with Nearby API should be perceived as a publish-discover flow rather than the standard send-receive communication.

Upvotes: 2

Related Questions