How to receive Incoming Messages using SMACK

Hi all, I read some examples and tested them but all of them need to start a chat with someone first to receive Incoming Messages… I want to retrieve this Incoming Messages without need to talk first to the jid anyone can give an example ?

thx for ur time.

If you want to receive the chat messages unprompted, you will have to register a ChatManagerListener with the ChatManager. It will be called whenever a new chat is initiated from an incoming chat message. Don’t have sample code to show you right now, but it isn’t too hard to figure out.

if u do like this u can recive the incomming messages

it worked for me so u try it

public PrivateMessageListener(XMPPConnection connection) {

// register listeners

//ChatManager chatmanager = connection.getChatManager();

connection.getChatManager().addChatListener(new ChatManagerListener() {

public void chatCreated(final Chat chat, final boolean createdLocally) {

chat.addMessageListener(new MessageListener() {

public void processMessage(Chat chat, Message message) {

//JOptionPane.showMessageDialog(null, "Rec: For " + chat.getParticipant() + " from " + message.getFrom() + “\n” + message.getBody());

String sender=message.getFrom();

String senderNames=sender;

System.out.println("Received message: " + (message != null ? message.getBody() : “NULL”));

PrivateChatManager.receiveMessage(sender, senderNames, message.getBody());

}

});

}

});

wat does privatechat manager contain???

It’s not relevant, and should probably not be included in that example to keep it simple. That is just some application specific code.

The example just shows the creation of a ChatManagerListener which will receive notifications when a new chat is created.