Skip to content Skip to sidebar Skip to footer

What Is The Uri For Wearable.dataapi.getdataitem() After Using Putdatamaprequest?

I'm testing the Wearable Data Layer Api as described in the Android tutorial. There is a low level API based around DataItem, which can have only a byte array as payload, so the tr

Solution 1:

The uri's authority (which is described as <some guid here> in your post) is Node Id which is available via Node API. In summary, you can construct the Uri as following.

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;
}

Post a Comment for "What Is The Uri For Wearable.dataapi.getdataitem() After Using Putdatamaprequest?"