powered by Jive Software

ChatStateListener doesn't work

Hi guys,

I’m using Smack 4.1 for Android application. I want to using the ChatStateListener to detect typing status. But i got nothing in stateChanged. But when I try use other Xmpp app, it can detect typing status.

Here is my code

public class CustomMessageListener implements ChatMessageListener,ChatStateListener {
    private Context context;     public CustomMessageListener(Context context) {
        this.context = context;
    }
    @Override
    public void processMessage(Chat chat, Message message) {
        Log.d("XMPP",message.toXML().toString());
        if (message.getBody() != null) {
            // do somthing
        }
    }     @Override
    public void stateChanged(Chat chat, ChatState state) {
        Log.d("XMPP","chat state change  : " + state.name());
        if (ChatState.composing.equals(state)) {
            Log.d("XMPP",chat.getParticipant() + " is typing.");
        } else if (ChatState.gone.equals(state)) {
            Log.d("XMPP",chat.getParticipant() + " has left the conversation.");
        } else {
            Log.d("XMPP",chat.getParticipant() + ": " + state.name());
        }
    }
}

And I always set the typing satus when message editor on changed. But why as I see the stateChanged never raise. Please help me.

Thanks

Just add ChatStateManager after ChatManager intalization

chatManager = ChatManager.getInstanceFor(getXmpptcpConnection());

ChatStateManager.getInstance(getXmpptcpConnection());

then you need add ChatStateListener during createChat(to,chatMesageListener)

chatManager.createChat(message.getTo(), chatMessageListener).sendMessage(message);

private ChatStateListener chatMessageListener = new ChatStateListener() {

@Override

public void stateChanged(Chat chat, ChatState state) {

//State Change composing,active,paused,gone,etc

Log.d(TAG, "ChatStateListener:::stateChanged -> " + chat.toString() + " \n -> " + state.toString());

}

@Override

public void processMessage(Chat chat, Message message) {

//Incoming Message

Log.d(TAG, "ChatStateListener:::processMessage -> " + chat.toString() + " \n -> " + message.toString());

}

};