horro
horro

Reputation: 1309

Android Nearby - Connections vs Messages API

I am currently working on a simple app to exchange little messages between anonymous people but colocated. This collocated interaction is the main reason to use Nearby API. However, I have been reading Connections API and Messages API but I still do not know which of them would fit better for my app.

Just to be clearer, the basic flow of the app would be something like:

  1. Discover new devices and list them
  2. Select one of them
  3. Send messages to the selected device

Is this possible just using Messages API? I think Connections API can manage this scenario since you first establish a connection with another device, but the devices must be on the same WiFi network. However, with Messages, devices do not have to be on the same WiFi connection.

Basically, I would like to not depend on WiFi to communicate. Besides, some WiFis could have some kind of firewall to block this kind of traffic.

Upvotes: 1

Views: 1067

Answers (1)

MahlerFive
MahlerFive

Reputation: 5279

If you need it to work without everyone being on the same multicast-enabled WiFi network - then Connections API is out as a possibility.

You can use the Messages API to discover other devices that are nearby and send messages, however, the messages are broadcast to everyone. You could use a more complex messaging scheme to encrypt messages that can only be decrypted by the intended recipient by publishing your public key when you subscribe.

One other thing to know when considering using the Nearby APIs is whether or not it is acceptable that all participants need to have the app open in the foreground for it to work. This is because you can't be subscribing and publishing all the time without significant battery drain. When it comes to a generic messaging app - this restriction would probably prevent you from using Nearby as a solution.

Upvotes: 2

Related Questions