public class Chat extends Object
| Modifier and Type | Method and Description |
|---|---|
void |
addMessageListener(MessageListener listener)
Adds a packet listener that will be notified of any new messages in the
chat.
|
void |
close()
Closes the Chat and removes all references to it from the
ChatManager. |
PacketCollector |
createCollector()
Creates a
PacketCollector which will accumulate the Messages
for this chat. |
boolean |
equals(Object obj) |
Collection<MessageListener> |
getListeners()
Returns an unmodifiable collection of all of the listeners registered with this chat.
|
String |
getParticipant()
Returns the name of the user the chat is with.
|
String |
getThreadID()
Returns the thread id associated with this chat, which corresponds to the
thread field of XMPP messages.
|
int |
hashCode() |
void |
removeMessageListener(MessageListener listener) |
void |
sendMessage(Message message)
Sends a message to the other chat participant.
|
void |
sendMessage(String text)
Sends the specified text as a message to the other chat participant.
|
String |
toString() |
public String getThreadID()
public String getParticipant()
public void sendMessage(String text) throws XMPPException, SmackException.NotConnectedException
Message message = chat.createMessage();
message.setBody(messageText);
chat.sendMessage(message);
text - the text to send.XMPPException - if sending the message fails.SmackException.NotConnectedExceptionpublic void sendMessage(Message message) throws SmackException.NotConnectedException
message - the message to send.SmackException.NotConnectedExceptionpublic void addMessageListener(MessageListener listener)
listener - a packet listener.public void removeMessageListener(MessageListener listener)
public void close()
ChatManager. The chat will
be unusable when this method returns, so it's recommend to drop all references to the
instance right after calling close().public Collection<MessageListener> getListeners()
public PacketCollector createCollector()
PacketCollector which will accumulate the Messages
for this chat. Always cancel PacketCollectors when finished with them as they will accumulate
messages indefinitely.