1

I have a wearable device from which data is sent to a handheld device wrapped in a DataMap object. On the handheld device I implemented a listener service that extends WearableListenerService implemented in this way:

public class ListenerService extends WearableListenerService {
    private static final String TAG = ListenerService.class.toString();

    private static final String WEARABLE_DATA_PATH = "/wearable_data";

    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        DataMap dataMap;

        for (DataEvent event : dataEvents) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String path = event.getDataItem().getUri().getPath();

                if (path.equals(WEARABLE_DATA_PATH)) {
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

                    messageReceived(dataMap);
                }
            }
        }
    }

    private void messageReceived(DataMap dataMap) {
        Log.v(TAG, "DataMap received on handheld device: " + dataMap);
    }
}

The transmission from wearable to handheld works flawlessly. However, I would need to send back from handheld to wearable an answer, like "ok done" or "error xxx". How can I do that?

Dev
  • 7,027
  • 6
  • 37
  • 65

1 Answers1

2

it works the same way. You need a subclass of WearableListenerService on your wearable app, declared it on your AndroidManifest.xml, with the action com.google.android.gms.wearable.BIND_LISTENER. When the handheld is ready send a Message to the Wearable, you can use either the DataApi or the MessageApi and corresponding callback will be invoked on the other endpoint

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • That's exactly what I feared. Is there not any other more convenient solution? It seems to me weird to manage "simple" answers in this way... – Dev May 29 '15 at 12:23
  • you could send another notification to the wearable, if you are already handling local notifications of both ends, but I would look really weird imo – Blackbelt May 29 '15 at 12:25
  • 2
    The communication is asynchronous which means there is no simple acknowledgment of whatever you send to the wearable. Blackbelt's answer is IMO the correct one. – Emanuel Moecklin May 30 '15 at 16:43