Hey I am trying to get typing status when the other person starts writing even though it is returning an empty message with the state as a message but it is coming from proccessMessage method. Shouldn't it be returned in the stateChanged? I haven't enabled any PacketProvider though, Do i have to do it so this would be returned in the stateChanged method? I would appreciate any help.
newChat = chatmanager.createChat(contactUsername + sc.DOMAIN, new ChatStateListener() {
@Override
public void stateChanged(Chat chat, ChatState state) {
if (ChatState.composing.equals(state)) {
Log.d("Chat State",chat.getParticipant() + " is typing..");
} else if (ChatState.gone.equals(state)) {
Log.d("Chat State",chat.getParticipant() + " has left the conversation.");
} else {
Log.d("Chat State",chat.getParticipant() + ": " + state.name());
}
}
@Override
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});
Logs:
06-15 14:28:47.679 9949-9983/com.example.example I/System.outīš Received message: <message to='[email protected]' from='[email protected]/Spark 2.6.3' id='AUJG0-42' type='chat'><thread>097uC9</thread><inactive xmlns='http://jabber.org/protocol/chatstates'/></message>
This is a general answer, there might be better ones, but this works for sure, it might contain stuff you already know, but I guess it can't hurt.
Base assumption -
composing
messages are messages where the body is null, and the xml of the whole message contains aChatState
tag with one ofactive, composing, paused, inactive, gone
values, and what you're looking for iscomposing
, and it's counterpart,paused
.That being said, on the receiving component you need something like this (modify it to your needs):
EDIT:
Your log message shows you got an
inactive
message, so for starters, try filtering all the messages, and find the pattern of what your looking for, to see if the sending side is even sending what you need.A good way to understand would be to use another client that you know for a fact that's sending the composing state, and see what you get in your filter (e.g. under linux you could use pidgin or empathy for the sending side).
EDIT 2:
As per requested, I'm also adding some of the sending-side components for a more complete picture, again, this is a general example for reference purpose, and could be optimized and changed.
First, implement a custom EditText that implements a TextWatcher with a small thread that fires with the delay you want from the last text change to say "I stopped typing", set your interval as you want:
Next, in the activity that handles your chat, add a new anonymous interface and implement it's callback with your state-changing-message sending method call, this part C of the magic, as this will send your state corresponding to the TextWatcher mini-thread:
And last but not least, in your connection handler class you should have the following:
Hope this Helps.