powered by Jive Software

Send composing message using SMACK


#1

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!!!


#2

I think what you are looking for is

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


#3

Thanks for answer.

Problem was solved.

Example:

  1. Create class MessagePacketExtension implements PacketExtension

public class MessagePacketExtension implements PacketExtension {

@Override

public String getElementName() {

return “composing”;

}

@Override

public String getNamespace() {

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

}

@Override

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)));

_packet.setTo(_to);

_sessionData.getXmppConnection().sendPacket(_packet);

All works!!!


#4

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


#5

Just add ChatStateManager after ChatManager intalization

chatManager = ChatManager.getInstanceFor(getXmpptcpConnection());

ChatStateManager.getInstance(getXmpptcpConnection());

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

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

private ChatStateListener chatMessageListener = new ChatStateListener() {

@Override

public void stateChanged(Chat chat, ChatState state) {

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

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

}

@Override

public void processMessage(Chat chat, Message message) {

//Incoming Message

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

}

};


#6

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


#7

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


#8

Yeah you are right. Thank you so much


#9

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.


#10

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


#11

Thx Paul,

Looking the source code I found how to do it.

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