Ramps
Ramps

Reputation: 5298

Nearby Connection API - device not advertising after disconnecting few times

I'm using so called Nearby Connections. One device is advertising (Nearby.Connections.startAdvertising() ) and another is discovering (Nearby.Connections.startDiscovery() ). This api works fine, I can successfully connect to the host device. However, if I disconnect, and reconnect few times, the device is not advertising any more. I'm calling Nearby.Connections.startAdvertising(), but onResult() method from PendingResult is not invoked at all. PendingResult is returned from Nearby.Connections.startAdvertising() method and you can use that to check if advertising started successfully. Did anyone have similar problem?

I have to reboot the device in order to advertising start working again. (reconnecting the wifi doesn't help).

Upvotes: 3

Views: 1057

Answers (2)

Neeraj Thakur
Neeraj Thakur

Reputation: 56

I would suggest to not keep Advertising your connection if you don't need it.

I would suggest to use stopAdvertising() when you start your session, and when you need to reconnect just send the host ConnectionRequest(...) again without advertising.

and in any case you need it you can again switch it on. if you want, you can try stopAdvertising() and then startAdvertising(...) and see if it works because I am using this method and it's working perfectly.

Hope it helped

Upvotes: 1

StefanTo
StefanTo

Reputation: 1020

When you start advertising, do you set a timeout? You can try to set 0 there:

Nearby.Connections.startAdvertising(mGoogleApiClient, hostNameString, appMetadata, 0l, this);

In the nearby-connection quickstart example, you can set these two variables:

private static final long TIMEOUT_ADVERTISE = 0L;
private static final long TIMEOUT_DISCOVER = 0L;

Upvotes: 0

Related Questions