Skip to content

Instantly share code, notes, and snippets.

@kzim44
Created September 19, 2014 16:34
Show Gist options
  • Save kzim44/7a38bdcf1637f683fae1 to your computer and use it in GitHub Desktop.
Save kzim44/7a38bdcf1637f683fae1 to your computer and use it in GitHub Desktop.
Code to calculate the full URI for a DataItem in the Wear SDK data store.
// From this stackoverflow answer: http://stackoverflow.com/a/24607116/468310
private Uri getUriForDataItem() {
// If you've put data on the local node
String nodeId = getLocalNodeId();
// Or if you've put data on the remote node
// String nodeId = getRemoteNodeId();
// Or If you already know the node id
// String nodeId = "some_node_id";
return new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).authority(nodeId).path("/path_to_data").build();
}
private String getLocalNodeId() {
NodeApi.GetLocalNodeResult nodeResult = Wearable.NodeApi.getLocalNode(mGoogleApiClient).await();
return nodeResult.getNode().getId();
}
private String getRemoteNodeId() {
HashSet<String> results = new HashSet<String>();
NodeApi.GetConnectedNodesResult nodesResult =
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
List<Node> nodes = nodesResult.getNodes();
if (nodes.size() > 0) {
return nodes.get(0).getId();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment