What is the Uri for Wearable.DataApi.getDataItem() after using PutDataMapRequest?

后端 未结 1 1655
一整个雨季
一整个雨季 2021-02-07 10:33

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

相关标签:
1条回答
  • 2021-02-07 10:40

    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;
    }
    
    0 讨论(0)
提交回复
热议问题