I'm using a GoogleApiClient
in my Android Wear app that in onResume
of the main activity connects and when it's connected it messages all connected nodes a message ("startservice" in this case) that my WearableListenerService
takes care of. Whenever it gets that message it immediately starts a request to my api and the response callback starts a PutDataMapRequest
and sends all my json objects (from response) via Wearable.DataApi.putDataItem(GoogleApiClient, PutDataRequest)
and when that triggers my WearableListenerService
in my Android Wear app it's calling onDataChanged(DataEventBuffer)
.
To clarify:
onResume
in Wear app sends 'startservice' to all connected nodes- 'startservice' is received on my handheld, starting a request
- Response from request ready, it connects to GoogleApiClient and sends it to the wear device
- The wear app does not get it or only gets it 1/10 times it's sent to it
The log from the Wear app looks like this:
Sending 'startservice' to node 'node id 1'
Sending 'startservice' to node 'node id 2'
Sending 'startservice' to node 'node id 3'
Sending 'startservice' to node 'node id 4'
And then on my handheld app log it looks like this:
Message 'startservice' received, getting objects..
Objects ready! Send response to Wear device!
And on the wear nothing happens.. The onDataChanged
is only called ~1/10 times!
Is this not the best way to send data to the wear device?
Edit:
If I set a resultcallback on the Wearable.DataApi.putDataItem()
the status of the result is SUCCESS
..
Edit 2: So it seems to be working every time the handheld app is in the foreground (or in any way active). Whenever the handheld app is closed it just does not send to the correct (or any) wear device. Is it possible to send to wear device from a service?