1

I'm experimenting a bit with Android Wear (streaming data from the watch to the phone) and I was looking into the CapabilityApi.

According to the documentation for Wearable.CapabilityApi.getCapability there is no guarantee that this call will only return connected nodes: https://developers.google.com/android/reference/com/google/android/gms/wearable/CapabilityInfo.html#getNodes()

What I wonder is, do I have to do something like the following:

final CapabilityApi.GetCapabilityResult result = 
    Wearable.CapabilityApi.getCapability(mGoogleApiClient, RECIEVE_SOUND_DATA_CAPABILITY, Wearable.CapabilityApi.FILTER_REACHABLE).await();
final NodeApi.GetConnectedNodesResult connectedNodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

for (final Node node : result.getCapability().getNodes()) {
    if (connectedNodes.getNodes().contains(node)){
        sendDataToNode(node, dataSender);
    }
}

In order to determine that the node is actually connected, or is it enough to call:

node.isNearby()

Prior to sending the data?

JohanShogun
  • 2,956
  • 21
  • 30

1 Answers1

3

When you use the FILTER_REACHABLE filter, you will only see a list of reachable (i.e. connected) devices on the network. Given the fact that connectivity can happen through the cloud, you would probably want to sort the returned list based on additional criteria, for example you may prefer those nodes that are "directly connected" (isNearBy()) to reduce the number of hops required to reach that node, or in some cases, you may need to declare additional capabilities (say, processor capabilities, or GPU capabilities, etc) and then find the most appropriate one among the connected devices.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28