Hello!
I am trying to develop a chat application for android and iOS in which I am using OpenFire as the chat server. OpenFire has already been setup on AWS. But I am facing a problem here. I cannot receive messages using Smack.
Also I need to know that if I receive messages using Smack then does it retrieves all messages in one go or it sends the latest message, when this receive API is called.
I am using this to get messages function not returning message list,
i am able to send message to server but cant receive message list.
ChatManager chatmanager = con.getChatManager();
Chat newChat = chatmanager.createChat(“user4@jmj-pc”,null);
newChat.addMessageListener(new MessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " +message.getBody());
}
});
try {
newChat.sendMessage(“message body, jmj!”);
}
catch (XMPPException e) {
System.out.println(“Error Delivering block”);
}
W.K
January 6, 2017, 6:45am
2
Hi!
Have you solved the problem? I got the same problem with you. If you have solved that, could you share your resolution please?
Hiren1
January 6, 2017, 12:08pm
3
There is also one more trick to catch all message of all user
create a class which should implement ChatManagerListener
public class ChatManager implements ChatManagerListener {
@Override
public void chatCreated(Chat chat, boolean createdlocally) {
chat.addMessageListener(new MessageListener() {
@Override
public void processMessage(Chat chat, Message Message) {
// Process your message here
}
}
}
}
now add this class as a chatListner to your xmpp connection
ChatManager chatManager = new ChatManager();
connection.getChatManager().addChatListener(chatManager);
You could also try below code
ChatManager chat = connection.getChatManager();
chat.createChat(jid, new MessageListener() {
@Override
public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message arg1) {
}
}).sendMessage(message);
Hope this will work
1 Like
W.K
January 6, 2017, 2:30pm
4
Thanks for your response.
I have missed MessageListener in chatCreated(Chat chat, boolean createdlocally) method.
Your resolution works well, thanks again.
1 Like