5

I'm synchronizing events between the wearable and the smartphone. Since I want that my events are recieved by the phone even if they are disconnected I started using the DataAPI instead of the MessageAPI, but now the "synchronization" takes about 1-2 seconds instead of 0.1-0.5 seconds (perceived timings).

I'm transmitting in case of the messages a string path like "/notification/click" and two bytes of raw data. In case of the DataAPI I use the path "/notification/click/1" and one byte of raw data. Did you see that behavior too? Do you know a trick to fasten that up, except to use the DataAPI only if the device is offline?

If you want to see some code please leave a comment. Since that code has much boilder plate code I did not add it (yet).

rekire
  • 47,260
  • 30
  • 167
  • 264
  • I'm finding it incredibly slow. What did you do in the end? – StuStirling Nov 24 '15 at 17:53
  • Oh I need to review this question. That huge dalay was some kind of bug which was gone after some time. However I use many bit operations to reduce the amount of data to transfer. Does this help you? – rekire Nov 24 '15 at 17:58
  • Thanks for the reply. The issue I'm having is I am saving things fine to the data api on the mobile end. I am connecting fine on the wear end in a WearableListenerService but it's only occasionally being called. – StuStirling Nov 24 '15 at 18:03
  • Just had to submit a question http://stackoverflow.com/questions/33900980/is-dataapi-reliable-and-practically-real-time-extremely-delayed. Is that right? If you don't delete data `onDataChanged` won't be called? – StuStirling Nov 24 '15 at 18:19

2 Answers2

2

You can check, if you are connected by looking up connected nodes NodeApi.getConnectedNodes() and seeing, if it's not empty. But I don't think this is the best solution.

If you need a both fast and reliable delivery of information, send both a message and set a data item. Add a unique identifier to both, so you can ignore the one, that gets delivered second. This way if you are connected, you will receive a message quickly and later ignore the data item. If you are not connected, the message will be lost, but the data item will persist and eventually will make you complete the action. You will need to persist the unique identifiers though to handle following case:

  1. message delivered, action completed,
  2. reboot for whatever reason,
  3. data item eventually delivered, needs to be ignored.
gruszczy
  • 40,948
  • 31
  • 128
  • 181
0

yes, in my test result, data API is slower than message api(not a few time, two times above),you can try a way to increase your message speed. data api has a feature that it can send an asset which support the data size can larger than 100KB, but message api can not support data size which is larger than 100KB. use a common interface of send message, check the data size you want send, if large than 100KB, use data api asset to send, if not, use message api. this is my to speed up my app

Jimmy Chen
  • 177
  • 5