I am building a chat application using asmack xmpp client. Chat works fine and I have implemented ChatStateListener
but stateChanged
method never gets called. Currently to get composing status I am parsing the message xml. Below is the message format for composing,text, active.
<message id='5ec7d' to='[email protected]' from='[email protected]/682e3641' type='chat'><composing xmlns="http://jabber.org/protocol/chatstates" /></message>
<message id='9a93f22' to='[email protected]' from='[email protected]/682e3641' type='chat'><body>hi</body><active xmlns="http://jabber.org/protocol/chatstates" /></message>
<message to='[email protected]' from='[email protected]/682e3641' type='chat'><active xmlns="http://jabber.org/protocol/chatstates" /></message>
But parsing xml to get the composing status is not a good idea. Can someone help me to understand why stateChanged
never get called.
I am working on a project right now using aSmack as well, this is how I solved the problem, hopefully it helps you out. I assume that you have created an instance of ChatStateManager such as:
Then to send the composing state, where connection is your current xmpp connection and currentChat is the Chat you created for the current conversation
The other client will send you a Packet with the different states, in the case below is a composing state
Now this is where it gets fun, (to answer your question). I grab every incoming Packet and send it to a BroadcatsReceiver to notify me of it. Note that if the incoming packet has a null body that means it's not an actual message with text but a ChatState message.
And
I know this might be just a "workaround" and if somebody reading this has a better answer please post it so we can all learn from it.
Thank you and I hope it helps.