What you want do do here is to add an extension to your text message. Here is a rough guide.
Chat chat = connection.getChatManager().createChat(to, this);
Message message = new Message(to, Message.Type.chat);
message.setBody("hello");
message.setProperty(prop0, val0);
message.setProperty(prop1, val1);
chat.sendMessage(message)
The properties are carried in a separate namespace (use toXML()
to look at it) and will not appear in the chat window. On the 'other side', the applications uses getProperty()
to retrieve the value.
If you do not want key/value pairs, but structured data, use addExtension()
in the message body. This is a little more complicated because you basically have to extend PacketExtension
, provide your own namespace. You might even have to write a PacketExtensionProvider
.