0

I know this is a duplicate question but i am new in xmpp chat and getting one side only typing status, I want Typing status both side sender and receiver. I am also search and use this link How to know Typing Status in XMPP openfire using Smack

this is my ChatMessageListener class

private class MMessageListener implements ChatMessageListener, ChatStateListener {

    public MMessageListener(Context contxt) {
    }

    @Override
    public void processMessage(final org.jivesoftware.smack.chat.Chat chat,
                               final Message message) {
        Log.e("Msg Received", "Xmpp message received: '" + message);


    }

    @Override
    public void stateChanged(Chat chat, ChatState state) {
        Log.e("Chat State", "" + state);
        Intent intent = new Intent(MESSAGE_RECEIVE_BROADCAST);
        if (ChatState.composing.equals(state)) {
            intent.putExtra("chatState", "" + chat.getParticipant() + " is typing..");
        } else if (ChatState.gone.equals(state)) {
            intent.putExtra("chatState", "" + chat.getParticipant() + " has left the conversation.");
        } else {
            intent.putExtra("chatState", "" + chat.getParticipant() + ": " + state.name());
        }
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

}

i have also include Textwatcher on edittext to send typing state to receiver

edtMsg.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            ChatListActivity.getmService().xmpp.setCurrentState();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

this is my setCurrentState

public void setCurrentState() {
    try {
        if (!chat_created) {
            if(mMessageListener == null)
                mMessageListener = new MMessageListener(context);
            Mychat = ChatManager.getInstanceFor(connection).createChat(
                    SharedPreferenceUtil.getString(ChatUtils.XMPP_RECEIVER, "") + "@"
                            + context.getString(R.string.server),
                    mMessageListener);
            chat_created = true;
        }
        ChatStateManager.getInstance(connection).setCurrentState(ChatState.composing, Mychat);
    } catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
    }
}

If any kind of help will be appreciated.

Community
  • 1
  • 1
Mohit Suthar
  • 8,725
  • 10
  • 37
  • 67

0 Answers0