powered by Jive Software

Send composing message using SMACK

Hi All!

Tell me please how I can send message of this type: <composing xmlns='http://jabber.org/protocol/chatstates’/> ???

Example code would be very good

Thank for answer!!!

I think what you are looking for is

ChatStateManager.getInstance(connection).setCurrentState(ChatState.composing, myChat);

Thanks for answer.

Problem was solved.


  1. Create class MessagePacketExtension implements PacketExtension

public class MessagePacketExtension implements PacketExtension {


public String getElementName() {

return “composing”;



public String getNamespace() {

    return "[http://jabber.org/protocol/chatstates](http://jabber.org/protocol/chatstates)";



public String toXML() {

    return "<composing xmlns='[http://jabber.org/protocol/chatstates'/](http://jabber.org/protocol/chatstates'/)>";



  1. Use it.

Message _packet = new Message();

_packet.addExtension(new MessagePacketExtension(getTypeNotification(req)));



All works!!!

You should probably try the existing solution instead of rolling your own.

Just add ChatStateManager after ChatManager intalization

chatManager = ChatManager.getInstanceFor(getXmpptcpConnection());


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

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

private ChatStateListener chatMessageListener = new ChatStateListener() {


public void stateChanged(Chat chat, ChatState state) {

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

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



public void processMessage(Chat chat, Message message) {

//Incoming Message

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



Thanks for your answer.

I am getting exception at the below line when processing packets

Message msg = (Message) packet;

org.jivesoftware.smack.packet.Presence cannot be cast to org.jivesoftware.smack.packet.Message

Not every Packet is a Message. You appear to be trying to cast a Presence into a Message, which is impossible.

1 Like

Yeah you are right. Thank you so much

Hi guys,

@Paul_Schaub do you have an example of this with 4.2.4 or 4.3.0-rc1 but for sending? (incoming one is easy)
I mean, I’m trying something like @Dastanlqbal said but it seems it has changed a little bit.

Please take a look at the chatstates package in smacks experimental (or was it smacks extensions?), the code should be pretty self explanatory.

Thx Paul,

Looking the source code I found how to do it.

ChatStateManager.getInstance(connection).setCurrentState(ChatState.composing, chat)

1 Like