To enable ChatStateListener
you need to create a custom MessageListener
Class
public class MessageListenerImpl implements MessageListener,ChatStateListener {
@Override
public void processMessage(Chat arg0, Message arg1) {
System.out.println("Received message: " + arg1);
}
@Override
public void stateChanged(Chat arg0, ChatState arg1) {
if (ChatState.composing.equals(arg1)) {
Log.d("Chat State",arg0.getParticipant() + " is typing..");
} else if (ChatState.gone.equals(arg1)) {
Log.d("Chat State",arg0.getParticipant() + " has left the conversation.");
} else {
Log.d("Chat State",arg0.getParticipant() + ": " + arg1.name());
}
}
}
Then you create MessageListener
object
MessageListener messageListener = new MessageListenerImpl();
And then pass this in the create chat method
Chat newChat = chatmanager.createChat(jabber_id_of_friend, messageListener);
what is difference between Smack and asmack? <-- Check This
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…