I believe when you iterate over your nodes in the background thread that this is unnecessary.
Correct me if I'm wrong but I think there is a single DataApi instance that is shared across all nodes so if you make a change to the api once then all nodes connected would be notified through onDataChanged.
At the moment you're not using the Node for anything other than displaying the node's display name. It doesn't mean that that node has been updated however.
This is the code I'm talking about.
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await();
for (Node node : nodes.getNodes()) {
// Construct a DataRequest and send over the data layer
PutDataMapRequest putDMR = PutDataMapRequest.create(path);
putDMR.getDataMap().putAll(dataMap);
PutDataRequest request = putDMR.asPutDataRequest();
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleClient,request).await();
if (result.getStatus().isSuccess()) {
Log.v("myTag", "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
} else {
// Log an error
Log.v("myTag", "ERROR: failed to send DataMap");
}
}
Hi,
I believe when you iterate over your nodes in the background thread that this is unnecessary.
Correct me if I'm wrong but I think there is a single DataApi instance that is shared across all nodes so if you make a change to the api once then all nodes connected would be notified through onDataChanged.
At the moment you're not using the
Node
for anything other than displaying the node's display name. It doesn't mean that that node has been updated however.This is the code I'm talking about.