danny11
danny11

Reputation: 483

Nearby Connections no ConnectionResponseCallback

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.

Upvotes: 3

Views: 683

Answers (2)

qua
qua

Reputation: 53

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

Upvotes: 0

Neeraj Thakur
Neeraj Thakur

Reputation: 56

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

Upvotes: 1

Related Questions