本文整理匯總了Java中org.jivesoftware.smack.MessageListener類的典型用法代碼示例。如果您正苦於以下問題:Java MessageListener類的具體用法?Java MessageListener怎麽用?Java MessageListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageListener類屬於org.jivesoftware.smack包,在下文中一共展示了MessageListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChat
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
private Chat getChat() {
if (chat == null) {
chat = ChatManager.getInstanceFor(con).createChat(getUserId(),
new MessageListener() {
@Override
public void processMessage(Chat c, Message m) {
if (chat != null && listener != null) {
listener.onMessage(instance, m.getBody());
}
}
});
}
return chat;
}
示例2: sendMessage
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
private void sendMessage(String to,String message){
/*
* this sends a message to someone
* @param to the xmmp-account who receives the message, the destination
* @param message: yeah, the text I'm sending...
*/
ChatManager chatmanager = conn.getChatManager();
Chat newChat = chatmanager.createChat(to, new MessageListener() {
public void processMessage(Chat chat, Message m) {
}
});
try {
newChat.sendMessage(message);
}
catch (XMPPException e) {
System.out.println("Error Delivering block" +e);
}
}
示例3: createChat
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
/**
* 創建聊天
* @param xmppConnection
* @param toUser
* @param messageListener
* @return
*/
public static Chat createChat(XMPPConnection xmppConnection,String toUser,MessageListener messageListener){
// 獲取當前登陸用戶的聊天管理器
ChatManager chatManager = xmppConnection.getChatManager();
// 為指定用戶創建一個chat,MyMessageListeners用於監聽對方發過來的消息 */
Chat chat = chatManager.createChat(toUser+"@" + SERVERNAME, messageListener);
return chat;
}
示例4: createChat
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
/**
* 創建聊天
* @param xmppConnection
* @param toUser
* @param messageListener
* @return
*/
public static Chat createChat(XMPPConnection xmppConnection,String toUser,MessageListener messageListener){
// 獲取當前登陸用戶的聊天管理器
ChatManager chatManager = xmppConnection.getChatManager();
// 為指定用戶創建一個chat,MyMessageListeners用於監聽對方發過來的消息 */
Chat chat = chatManager.createChat(toUser+"@" + SERVERNAME, messageListener);
return chat;
}
示例5: sendMessage
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
void sendMessage(Chat chat, Message message) throws NotConnectedException {
for(Map.Entry<MessageListener, StanzaFilter> interceptor : interceptors.entrySet()) {
StanzaFilter filter = interceptor.getValue();
if(filter != null && filter.accept(message)) {
interceptor.getKey().processMessage(message);
}
}
// Ensure that messages being sent have a proper FROM value
if (message.getFrom() == null) {
message.setFrom(connection().getUser());
}
connection().sendStanza(message);
}
示例6: fireNewChatState
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
private void fireNewChatState(Chat chat, ChatState state) {
for (MessageListener listener : chat.getListeners()) {
if (listener instanceof ChatStateListener) {
((ChatStateListener) listener).stateChanged(chat, state);
}
}
}
示例7: sendMessage
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
public void sendMessage(XMPPMessage xmppMessage) throws XMPPException {
ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat(xmppMessage.getTo(), new MessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
// No need to implement
}
});
LOG.debug("Sending message '" + xmppMessage.getMessage() + "' to " + newChat.getParticipant());
newChat.sendMessage(xmppMessage.getMessage());
}
示例8: shouldSendMessage
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
@Test
public void shouldSendMessage() throws XMPPException {
adapter.connect();
XMPPMessage xmppMessage = new XMPPMessage();
ChatManager chatmanager = mock(ChatManager.class);
Chat chat = mock(Chat.class);
when(connection.getChatManager()).thenReturn(chatmanager);
when(chatmanager.createChat(eq(xmppMessage.getTo()), any(MessageListener.class))).thenReturn(chat);
adapter.sendMessage(xmppMessage);
verify(chat).sendMessage(xmppMessage.getMessage());
}
示例9: createChat
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
@Override
public Chat createChat(String toUser, MessageListener messageListener) {
return XMPPUtil.createChat(xmppConnection, toUser, messageListener);
}
示例10: addOutgoingMessageInterceptor
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
public void addOutgoingMessageInterceptor(MessageListener messageInterceptor, StanzaFilter filter) {
if (messageInterceptor == null) {
return;
}
interceptors.put(messageInterceptor, filter);
}
示例11: getMessageListener
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
protected MessageListener getMessageListener() {
return messageListener;
}
示例12: createChat
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
/**
* 創建聊天
* @param toUser
* @param messageListener
* @return
*/
Chat createChat(String toUser, MessageListener messageListener);
示例13: addMessageListener
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
/**
* Adds a stanza(/packet) listener that will be notified of any new messages in the
* group chat. Only "group chat" messages addressed to this group chat will
* be delivered to the listener. If you wish to listen for other packets
* that may be associated with this group chat, you should register a
* PacketListener directly with the XMPPConnection with the appropriate
* PacketListener.
*
* @param listener a stanza(/packet) listener.
* @return true if the listener was not already added.
*/
public boolean addMessageListener(MessageListener listener) {
return messageListeners.add(listener);
}
示例14: removeMessageListener
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
/**
* Removes a stanza(/packet) listener that was being notified of any new messages in the
* multi user chat. Only "group chat" messages addressed to this multi user chat were
* being delivered to the listener.
*
* @param listener a stanza(/packet) listener.
* @return true if the listener was removed, otherwise the listener was not added previously.
*/
public boolean removeMessageListener(MessageListener listener) {
return messageListeners.remove(listener);
}
示例15: createPrivateChat
import org.jivesoftware.smack.MessageListener; //導入依賴的package包/類
/**
* Returns a new Chat for sending private messages to a given room occupant.
* The Chat's occupant address is the room's JID (i.e. [email protected]/nick). The server
* service will change the 'from' address to the sender's room JID and delivering the message
* to the intended recipient's full JID.
*
* @param occupant occupant unique room JID (e.g. '[email protected]/Paul').
* @param listener the listener is a message listener that will handle messages for the newly
* created chat.
* @return new Chat for sending private messages to a given room occupant.
*/
public Chat createPrivateChat(String occupant, MessageListener listener) {
return connection.getChatManager().createChat(occupant, listener);
}