I have wrote these codes, cause I want to receive and log the which from the specified entityJid. But I get nothing.
/*******************************************************************/
XmppManager.getChatManager().createChat(entityJid, new ChatMessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
LogUtils.d(“received:” + message.toXML().toString());
}
});
/*******************************************************************/
When I am reading the source code, I found these code, yes, it is the constructor of ChatManager, please focus on the red bold lines:
/*******************************************************************/
private ChatManager(XMPPConnection connection) {
super(connection);
// Add a listener for all message packets so that we can deliver
// messages to the best Chat instance available.
connection.addSyncStanzaListener(new StanzaListener() {
public void processPacket(Stanza packet) {
Message message = (Message) packet;
Chat chat;
** if (message.getThread() == null) {**
** // CHECKSTYLE:OFF**
** chat = getUserChat(message.getFrom());**
** // CHECKSTYLE:ON**
** }**
** else {**
** chat = getThreadChat(message.getThread());**
** }**
if(chat == null) {
chat = createChat(message);
}
// The chat could not be created, abort here
if (chat == null)
return;
deliverMessage(chat, message);
}
}, packetFilter);
INSTANCES.put(connection, this);
}
/*******************************************************************/
and I have noticed that the Chat is get by message’s threadId first ,Why? And because of this, my messagelistener I have set before did not been call.what’s more , I also test that: chat.sendMessage , and the messagelistener didn’t been call too. So , What is the meaning of ChatManager.createChat(EntityJid, ChatMessageListener) in newest verson of smack ? Can anyone help me out of this ?