0

I have an ArrayList of parcelable custom items:

ArrayList<AudioLog> audioLogs = getAudioLogs();

I want to send this from the watch to the phone using the MessageAPI:

Wearable.MessageApi.sendMessage(googleClient, node.getId(), path, audioLogs).await();

BUT, I need to convert the entire ArrayList and its contents to a byte[], as the sendMessage method takes - (GoogleClient client, int id, String path, byte[] message).

To convert each of my parcelable AudioLog objects, I have a custom Util class that marshals and unmarshals each of them to a byte[]. I just need a similar class that can convert the whole ArrayList and its contents to a byte[] in the one go, if that's possible, thanks.

Highway62
  • 800
  • 1
  • 10
  • 25

1 Answers1

1

You should create a DataMap object, which can be converted into a byte array.

DataMap audioLogMap = new DataMap();
ArrayList<DataMap> audioLogArrayList = new ArrayList<>();
for (AudioLog audioLog: audioLogs) {
    DataMap audioLogMap = new DataMap();
    //TODO: copy something from audioLog to audioLogMap
    audioLogArrayList.add(audioLogMap);
}
audioLogMap.putDataMapArrayList("key", audioLogArrayList);
byte[] audioLogByteArray = audioLogMap.toByteArray();
kazhik
  • 556
  • 1
  • 5
  • 7