SAP APIs - How to send Icon/Array from phone to watch

Hi there,

I am working on a project using Samsung accessory protocol which is usually called “Companion app”. I includes 2 parts:

  1. Android app to send data.
  2. Tizen web APIs: watch app to receive and show data.

As provided in Samsung sample apps, I understand that we can send String data like this:

private ServiceConnection mConnectionHandler = null;
...
this.mConnectionHandler = (ServiceConnection) socket;
...
public boolean sendData(final String data) {
    boolean retvalue = false;
    if (mConnectionHandler != null) {
        try {
            mConnectionHandler.send(getServiceChannelId(0), data.getBytes());
            retvalue = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        addMessage("Sent: ", data);
    }
    return retvalue;
}

Then, in watch app using Web APIs, I receive data like this:

 dataOnReceive =  function dataOnReceive (channelId, data) {
        var newData;

        if (!SAAgent.channelIds[0]) {
            createHTML("Something goes wrong...NO CHANNEL ID!");
            return;
        }
        newData = data + " :: " + new Date();

        /* Send new data to Consumer */
        SASocket.sendData(SAAgent.channelIds[0], newData);
        createHTML("Send massage:<br />" +
                    newData);
    };

The above codes work perfectly. But in my case, I need to send a data including 2 parts:

  1. A String
  2. An Drawable Icon:

import android.graphics.drawable.Icon;

It seems like the function always considers the data as a simple string:

dataOnReceive =  function dataOnReceive (channelId, data) {
    newData = data + " :: " + new Date();

So my question is: How to send string and Icon at the same time, how to retrieve and separate them in Web APIs so that I can display a text and an Icon on my watch app? Can we send a json data so that It can be easier to process in Web APIs?

Thank you very much!

Sorry for my bad question. We can just convert an object to json format then send the json as a string. Finally, in Web API, we can use javascript to parse the string to object by JSON.parse();

 JSONObject obj = new JSONObject();
 obj.put("title", titleString);
 obj.toString()

For the icon, convert the icon to bitmap, then convert bitmap to base64 format and embed along with the json mentioned above.

I’ve resolved the issue.

It is easy. An icon/image convert to Base64. Finally string and text add to JSON Object or send direct using delimeter like “string1_icon | string2_text” . Char | is your delimeter
or send as JSON like:
var json = {};
json.text = string1_text;
json.icon = string2_icon;
var outdata = JSON.stringify( json );