Created
September 19, 2014 16:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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