3

I'm using Nearby Connections API in Android. It's working fine except cases where there is a sudden disconnections.

The client again succeed in finding the endpoint, using the discovery process, yet when he uses sendConnectionRequest() Connections.ConnectionResponseCallback never called no matter if I restart the app both on the client and on the endpoint. Only when I restart both devices the connection start to work again.

I have 20+ devices on the client side so there might be connection between the two things.

Any help on issue or where to start debugging the issue would be great.

goblin
  • 1,513
  • 13
  • 13
danny11
  • 483
  • 1
  • 5
  • 12
  • I run into the same problem. I have the strong feeling that the Google Play Services are continuing in the background to advertise - but disallow a connection and also disallowing to let the app advertise again or something like this. Instead of restarting the device you can also clear all data (!) in the Google Play Services manually (cache is not enough). If you've found a solution, let us pls know. – Chris Feb 16 '16 at 13:01

2 Answers2

1

For making a connection in Nearby Connection API, the client don't just sends connection request, but Host also has to accept it-

Nearby.Connections.acceptConnectionRequest(mGoogleApiClient, remoteEndpointId, myPayload, this);

or reject it-

Nearby.Connections.rejectConnectionRequest(mGoogleApiClient, remoteEndpointId);

try this, and in your connection response callback have conditions to do stuff

if(status.isSuccess()){
   // Successful connection
} else {
  // Failed connection
}

Hope it helped

0

You need to properly disconnect the connection when needed with;

Nearby.Connections.disconnectFromEndpoint(mGoogleApiClient, remoteEndpointId);

or;

Nearby.Connections.stopAllEndpoints(mGoogleApiClient);

https://developers.google.com/nearby/connections/android/manage-connections

qua
  • 33
  • 1
  • 5