user2968401
user2968401

Reputation: 945

Android Wear: How to send multiple items with MessageApi?

So i want to use the MessageApi and not the DataApi to send multiple items to the wearable. However the sendMessage() of the MessageApi only allows a byte array to be sent.

For reference:

Wearable.MessageApi.sendMessage(mGoogleApiClient,
                             String id,
                             String path,
                             byte[] bytes)

My guess would be to create an array of byte arrays and then serialize that into one big byte array and send it off.

To make things clearer these are the steps in pseudo code:

byte[][] arrayOfByteArrays;
String a --> convert to byte[];
Bitmap b --> convert to byte[];

Add a and b byte[]'s to arrayOfByteArrays;
Serialize arrayOfByteArrays to just a byte[] and send it off;

Is this the correct approach? or Should I just call sendMessage() multiple times? Thanks.

Upvotes: 0

Views: 399

Answers (1)

Ali Naddaf
Ali Naddaf

Reputation: 19034

In general, it is more efficient (battery, bandwidth, ...) to send one message instead of multiple ones. However, there may be other factors involved in your specific case that may warrant sending multiple messages. Looking at your pseudo code, I noticed you are also trying to send a bitmap using the MessageApi. That, in general, is not the best approach to send across an image, or other types of assets; you can use Assets or you can use ChannelApi. Otherwise, the approach of serializing a bunch of small objects and putting them into one byte array and then desrializing at the other end would work; one simple way to do so (if dealing with simple objects) is to use json as a serialization means.

Upvotes: 1

Related Questions