0

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:

  1. onResume in Wear app sends 'startservice' to all connected nodes
  2. 'startservice' is received on my handheld, starting a request
  3. Response from request ready, it connects to GoogleApiClient and sends it to the wear device
  4. 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?

Jonas Borggren
  • 2,591
  • 1
  • 22
  • 40
  • Can you show the details of the Data Item that you use to send your response from the phone to the wear device? – Ali Naddaf Sep 19 '15 at 22:32
  • It's a string array that holds json objects. The path is correct. If this was incorrect it would never work, right? – Jonas Borggren Sep 20 '15 at 15:27
  • The reason I am asking is to see if each time you are trying to put a data item to be synced, whether the data item has the same content as the last time or it has a unique content each time. If it has the same content, you will not get a new onDataChanged() callback; if that could be the case, add a piece of timestamp to your data item and see if the call back gets invoked. – Ali Naddaf Sep 20 '15 at 17:24
  • Very good idea. Although I for now use messaging with MessageApi I will have to look into this later. Anyone who has a similar problem might try the message api. – Jonas Borggren Sep 22 '15 at 08:27

0 Answers0