Search code examples
androidgoogle-nearby

How does Google's nearby share discover devices that do not advertise themself?


Recently I was interested by the Nearby Share functionality and i started looking into the Google's Nearby Connections API.

The API uses a "advertise" and "discover" setup, where one of the devices advertises itself using the API and the other tries to discover all the devices nearby.

But, on the other hand, the Nearby Share functionality does not require a explicit "advertise" step.

My questions are the following:

  • how does a device sharing a file "discover" another device that is not explicitly "advertising" itself? Is it done in background always by the OS or is it using a different technique?
  • is it possible to skip the "advertise" step in the Nearby Connections API, like, apparently, does the Nearby Share functionality?

Solution

  • Nearby Share has a service that calls #startAdvertising (and rotates it every 10~15min).

    We have looked at ways to bootstrap NC. eg. Passing an IP:port or MAC address out of band (like through a QR code). But such an API hasn't been written yet. It can get complicated, since NC doesn't want to expose this raw information to clients, so how does the client know what to put in the QR code?