I'm using the Data API in a service for Android Wear in a watch face that pulls down data from the cloud in a phone app and syncs it through a DataMap to the paired watch app. But I'm a bit lost on how to get the service on the wearable side to properly listen to updates AND redraw its UI. Should I be doing this all from the same service?
I tried implementing the DataApi.DataListener methods in the private internal class that extends CanvasWatchFaceService.Engine, but that doesn't seem to work.
@Override
public Engine onCreateEngine() {
return new Engine();
}
private class Engine extends CanvasWatchFaceService.Engine implements DataApi.DataListener {
// other events and methods...
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
for(DataEvent event : dataEvents) {
DataItem dataItem = event.getDataItem();
if(PATH.equals(dataItem.getUri().getPath())) {
DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
downloadedTrends = dataMap.getString(DATAMAP_KEY);
}
}
}
@Override
public void onDraw(Canvas canvas, Rect bounds) {
// use the changed data here to update the watch face UI
}
}
Should I be using a separate service extending WearableListenerService, and if so, how do I extract the data in onDraw in the watch face service? Can I tap the DataEventBuffer directly outside of the callback?
I'm also think it might have something to do with the BIND_LISTENER intent filter in the manifest, since I'm implementing it on the private internal class.
Thanks for your help!