i'm developing an android application using quickblox api. I'm using chat SMACK functionality (1 to 1 chat) and i try receive message from chat. I can retrieve the message text, but i can't get customs parameters.
Here is a screen about my message variable:
The values i need are values stored in 'map' : tempo, telefono, stato, nome , prefisso.. how i can retrieve that? I just try to search on quickblox documentation, but i have an api error when try to implement DefaultPacketExtension.
Thank you
Here is an example how to do it using QuickBlox Android SDK 1.1
To send message with additional parameters:
Map<String, Object> addinfoParams = new HashMap<String, Object>();
addinfoParams.put(Consts.AGE, 22);
addinfoParams.put(Consts.TYPE, "actor");
final String BODY = "Hey QuickBlox!";
Message message = createMsgWithAdditionalInfo(USER_ID, BODY, addinfoParams);
Log.i(TAG, "message: " + message.toXML());
try {
qbPrivateChat.sendMessage(USER_ID, message);
} catch (XMPPException e) {
e.printStackTrace();
}
...
private Message createMsgWithAdditionalInfo(int userId, String body, Map<?, ?> addinfoParams){
Message message = new Message(QBChatUtils.getChatLoginFull(userId), Message.Type.chat);
String addInfo = ToStringHelper.toString(addinfoParams, "", Consts.ESCAPED_AMPERSAND);
MessageExtension messageExtension = new MessageExtension(Consts.QB_INFO, "");
try {
messageExtension.setValue(Consts.ADDITIONAL_INFO, addInfo);
} catch (BaseServiceException e) {
e.printStackTrace();
}
message.addExtension(messageExtension);
message.setBody(body);
return message;
}
To receive message and get custom parameters:
chatMessageListener = new ChatMessageListener() {
@Override
public void processMessage(Message message) {
String from = message.getFrom();
String messageBody = message.getBody();
List<MessageExtension> messageExtensions = message.getExtensions();
}
@Override
public boolean accept(Message.Type type) {
switch (type) {
case normal:
case chat:
case groupchat:
return true;
default:
return false;
}
}
};
More info in Chat snippets https://github.com/QuickBlox/quickblox-android-sdk/blob/master/snippets/src/com/quickblox/snippets/modules/SnippetsChat.java