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 training recommends using PutDataMapRequest
, which seems to be basically equivalent to a Bundle
(i.e. a serializable map) when using Intents. You basically create an instance of this class, then fill the values, and send it.
private final static String DATA_PATH = "/testdata";
PutDataMapRequest dataMap = PutDataMapRequest.create(DATA_PATH);
dataMap.getDataMap().putInt(...);
PutDataRequest request = dataMap.asPutDataRequest();
PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleApiClient, request);
pendingResult.setResultCallback(...);
Now, I want to check if this data was stored correctly (for testing, on the handheld itself, I'm not concerned about the wearable right now). The appropriate methods for this are in the DataApi
class, so I can call:
PendingResult<DataApi.DataItemResult> pending;
pending = Wearable.DataApi.getDataItem(mGoogleApiClient, uri);
pending.setResultCallback(...);
and then use DataMapItem.fromDataItem()
inside the callback to get the value.
The problem is: what is the actual Uri to request the DataItemResult?
The data is stored, because if I use Wearable.DataApi.getDataItems(mGoogleApiClient)
to iterate over all stored data, it's indeed there, and the Uri is:
"wear://<some guid here>/testdata"
And using this Uri with DataApi.getDataItem()
returns the correct result. But I'm clueless as to how to generate it, since I only used the /testdata
part to create the PutDataRequest
...
Or am I doing things incorrectly?