On the mobile device, from a Service, I'm using the same path to update a bitmap asset using the following code:
PutDataMapRequest dataMap = PutDataMapRequest.create("/result/1");
dataMap.getDataMap().putString(FIELD_NAME, name);
if(bitmap != null) {
Asset asset = createAssetFromBitmap(bitmap);
dataMap.getDataMap().putAsset(FIELD_IMAGE, asset);
}
PutDataRequest request = dataMap.asPutDataRequest();
PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi
.putDataItem(mGoogleApiClient, request);
DataApi.DataItemResult result = pendingResult.await(5L, TimeUnit.SECONDS);
On the wearable, I'm watching for changes as follows:
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
Log.d(TAG, "DataItem changed: " + event.getDataItem().getUri().toString());
...
dataEvents.release();
Now the first time it runs, I get one dataEvent. But, the next time I run it, I get 2 dataEvents with the same Uri, the old one and the new one. And so on.
I thought that using the same path in PutDatMapRequest.create() would simply update the data in the DataApi sync store, and sync it.
I've tried Wearable.DataApi.deleteDataItems() but this just gives me a big list of CHANGED and DELETED events, all with the same Uri.
How do I avoid getting loads of dataEvents on my wearable as time goes on?