0

I have been developing an app to read serial data from the micro usb port of the Samsung S4 using OTG cable. Now I want to send these data to the Android wear app runs on Galaxy Gear Live. The problem I face is that, I know we can send Strings to the android wear app using the message API, but how can I send a byte array to the gear app?

Any pointers are welcome. Thank you.

Akshika47
  • 135
  • 1
  • 6

1 Answers1

0

You need to use DataMap object. It is similar to Bundle, but is sent between the mobile and the wearable. So first you put a byte array into a the DataMap using DataMap.putByteArray and then serialize it to byte array itself by calling DataMap.toByteArray. Then you just send it using MessageApi.sendMessage.

You might notice, that MessageApi.sendMessage already accepts a byte array, so you could put your data directly there. However, you probably will want to add some metadata to your call. Even if not now, then in the future. It's best to future-proof your code and use the serialized DataMap.

gruszczy
  • 37,239
  • 27
  • 119
  • 167