1

I am building a chat application in Android. I send and receive message, but I don't know how can I know the other user status and typing status of the conversation.

I have been reading to use ChatManagerLister, but it is deprecated in this version.

In Smack 4.2 the class ChatManager does not have methods to listen chat states.

halfer
  • 19,824
  • 17
  • 99
  • 186
jamarfal
  • 53
  • 3

1 Answers1

0

Hi used chatstates ejabberd protocol for typing status. please read this doc might be helpful you XEP-0085: Chat State Notifications

For android side you need to implement following code

    Message msg= (Message) stanza;

    // below ChatStateExtension for Compossing message.
            ChatStateExtension state = (ChatStateExtension)msg.getExtension("http://jabber.org/protocol/chatstates");//jabber:x:event
            // if state (ChatStateExtension) !=null and is composing then call listener method if not error.
            if(state!=null) {
                Log.d(AppConstants.ELEMENT,"ChatStateExtension : " + state.toXML());
                if (state.getElementName().equals("composing")) {
                    if (msg.getType().equals(Message.Type.error)) {
                        return;
                    }

                    if (iCallBackForTypingListener != null) {
                        DelayInformation timestamp = (DelayInformation) msg.getExtension("delay", "urn:xmpp:delay");
                        if (timestamp == null)
                            timestamp = (DelayInformation) msg.getExtension("x", "jabber:x:delay");

                        if (timestamp != null && timestamp.getReason().equalsIgnoreCase("Offline Storage")){ //return if delay info is Offline Storage
                            return;
                        }


        //update your typing listener
    iCallBackForTypingListener.onTypingStanza(fromJID, typingSender);
                    }
//  xmpp.updateChatState(fromJID, state.getElementName(), sender);
                    return;
                } else if (state.getElementName().equals("paused")) {
                    return;
                }
Sagar Jethva
  • 986
  • 12
  • 26