我的可穿戴设备有一个Activity
,implements DataApi.DataListener
它会向手持设备Activity
发送一条消息onConnected()
以更新请求的数据。当手持设备收到此消息时,它会从服务器获取数据,并将其传递给DataMap
. 这DataMap
是使用以下代码发送的:
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
for(Node node : nodes.getNodes()) {
PutDataMapRequest dataRequest = PutDataMapRequest.create(mPath);
dataRequest.getDataMap().putDataMapArrayList("/path", mData);
PutDataRequest request = dataMapRequest.asPutDataRequest();
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
if(result.getStatus().isSuccess()) {
Log.d(TAG, "DataMap: " + mData + " sent to: " + node.getDisplayName());
}
}
这段代码似乎可以正常工作,因为它输出到 logcat: "DataMap: <mData> sent to: 7f7fbd33"
。然后手持AsyncTask
式可穿戴设备使用以下代码接收此数据:
NodeApi.GetLocalNodeResult localNode =
Wearable.NodeApi.getLocalNode(getGoogleApiClient()).await();
Uri dataUri = new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME)
.authority(localNode.getNode().getId()).path("/path").build();
Log.d(dataUri.toString());
DataApi.DataItemResult itemResult =
Wearable.DataApi.getDataItem(mGoogleApiClient, dataUri).await();
Log.d(TAG, itemResult.getStatus() + " dataItem=" + dataItem.getDataItem();
if(itemResult.getStatus().isSuccess() && itemResult.getDataItem() != null) {
...
}
路径似乎是正确的: wear://7f7fbd33/path
,但结果最终是: Status{statusCode=SUCCESS, resolution=null} dataItem=null
。为什么它给我一个空项目?