當前位置: 首頁>>代碼示例>>Java>>正文


Java Chat.sendMessage方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.Chat.sendMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java Chat.sendMessage方法的具體用法?Java Chat.sendMessage怎麽用?Java Chat.sendMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.Chat的用法示例。


在下文中一共展示了Chat.sendMessage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSendSimpleXHTMLMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
    * Low level API test.
    * This is a simple test to use with an XMPP client and check if the client receives the message
    * 1. User_1 will send a message with formatted text (XHTML) to user_2
    */
   public void testSendSimpleXHTMLMessage() {
// User1 creates a chat with user2
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);

// User1 creates a message to send to user2
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);

// User1 sends the message that contains the XHTML to user2
try {
    chat1.sendMessage(msg);
    Thread.sleep(200);
}
catch (Exception e) {
    fail("An error occured sending the message with XHTML");
}
   }
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:29,代碼來源:XHTMLExtensionTest.java

示例2: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的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);
	}

}
 
開發者ID:ControlAltDieliet,項目名稱:system_updater,代碼行數:21,代碼來源:Bot.java

示例3: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
long sendMessage(TextMessage textMessage) throws Exception {
	MultiUserChat muc = multichats.get(textMessage.getContactUid());

	if (muc != null) {
		Message m = muc.createMessage();
		m.setBody(textMessage.getText());
		muc.sendMessage(m);
		return m.getPacketID().hashCode();
	}

	Chat chat = chats.get(textMessage.getContactUid());
	if (chat == null) {
		chat = getInternalService().getConnection().getChatManager().createChat(textMessage.getContactUid(), this);
		chats.put(textMessage.getContactUid(), chat);
	}
	
	Message packet = getInternalService().getService().getEntityAdapter().textMessage2XMPPMessage(textMessage, chat.getThreadID(), chat.getParticipant(), Message.Type.chat);
	chat.sendMessage(packet);
	return packet.getPacketID().hashCode();
}
 
開發者ID:snuk182,項目名稱:aceim,代碼行數:21,代碼來源:XMPPChatListener.java

示例4: testSendSimpleXHTMLMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
    * Low level API test.
    * This is a simple test to use with a XMPP client and check if the client receives the message
    * 1. User_1 will send a message with formatted text (XHTML) to user_2
    */
   public void testSendSimpleXHTMLMessage() {
// User1 creates a chat with user2
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);

// User1 creates a message to send to user2
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);

// User1 sends the message that contains the XHTML to user2
try {
    chat1.sendMessage(msg);
    Thread.sleep(200);
}
catch (Exception e) {
    fail("An error occured sending the message with XHTML");
}
   }
 
開發者ID:bejayoharen,項目名稱:java-bells,代碼行數:29,代碼來源:XHTMLExtensionTest.java

示例5: onClick

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.btn_chat_send:
		try {
			//發送信息
			Chat chat = mXmppManager.createChat(mTargetJid);
			chat.sendMessage(mEtContent.getText().toString());
			
			//保存到數據庫
			ChatBean chatBean = new ChatBean();
			chatBean.setBody(mEtContent.getText().toString());
			chatBean.setFrom("wo");
			chatBean.setDirection(1);
			addChat(chatBean);
			
			mEtContent.getEditableText().clear();
			
		} catch (XMPPException e) {
			e.printStackTrace();
		}
		break;

	}
}
 
開發者ID:phoenixNirvana,項目名稱:NewCommunication-Android,代碼行數:26,代碼來源:ChatActivity.java

示例6: sendTo

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
public void sendTo(Player recipient, Command c) {
  Chat chat = conn.getChatManager().createChat(((JabberPlayer) recipient).getJid(), null);
  try {
    chat.sendMessage(encodeMessage(encoder.encode(c)));
  }
  // FIXME: review error message
  catch (XMPPException e) {
    reportXMPPException(e);
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:11,代碼來源:JabberClient.java

示例7: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
 * 發送消息
 * @param chat
 * @param message
 * @return
 */
public static boolean sendMessage(Chat chat,String message){
	try {
		chat.sendMessage(message);
		return true;
	} catch (XMPPException e) {
		e.printStackTrace();
		return false;
	}
}
 
開發者ID:FanHuaRan,項目名稱:SmackStudy,代碼行數:16,代碼來源:XMPPUtil.java

示例8: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
 * 發送消息
 * @param chat
 * @param message
 * @return
 */
public static boolean sendMessage(Chat chat, String message){
    try {
        chat.sendMessage(message);
        return true;
    } catch (XMPPException e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:FanHuaRan,項目名稱:SmackStudy,代碼行數:16,代碼來源:XMPPUtil.java

示例9: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
 * 發送消息
 * @param position
 * @param content
 * @param touser
 * @throws XMPPException
 */
public static void sendMessage(XMPPConnection mXMPPConnection,String content,String touser) throws XMPPException {
	if(mXMPPConnection==null||!mXMPPConnection.isConnected()){
		throw new XMPPException();
	}
	ChatManager chatmanager = mXMPPConnection.getChatManager();
	Chat chat =chatmanager.createChat(touser + "@" + Const.XMPP_HOST, null);
	if (chat != null) {
		chat.sendMessage(content);
		Log.e("jj", "發送成功");
	}
}
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:19,代碼來源:XmppUtil.java

示例10: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
synchronized public void sendMessage(String text, String id) {
	try {

		connect();

		String jabberID = getJabberID(id);

		// FIXME FIXME FIXME !!! - if
		// "just connected - ie just connected and this is the first chat of the connection then "create
		// chat" otherwise use existing chat !"
		Chat chat = null;
		if (chats.containsKey(jabberID)) {
			chat = chats.get(jabberID);
		} else {
			chat = chatManager.createChat(jabberID, this);
			chats.put(jabberID, chat);
		}

		log.info("chat threadid {} hashcode {}", chat.getThreadID(), chat.hashCode());

		if (text == null) {
			text = "null"; // dangerous converson?
		}

		// log.info(String.format("sending %s (%s) %s", entry.getName(),
		// jabberID, text));
		if (log.isDebugEnabled()) {
			log.info(String.format("sending %s %s", jabberID, (text.length() > 32) ? String.format("%s...", text.substring(0, 32)) : text));
		}
		chat.sendMessage(text);

	} catch (Exception e) {
		// currentChats.remove(jabberID);
		Logging.logError(e);
	}
}
 
開發者ID:glaudiston,項目名稱:project-bianca,代碼行數:37,代碼來源:XMPP.java

示例11: _sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
@Identifier("sendMessage")
@RequestResponse
public void _sendMessage( Value request )
	throws FaultException
{
	Chat chat = getChat( request.getFirstChild( "to" ).strValue() );
	try {
		chat.sendMessage( request.strValue() );
	} catch( XMPPException e ) {
		throw new FaultException( e );
	}
}
 
開發者ID:jolie,項目名稱:jolie,代碼行數:13,代碼來源:XMPPService.java

示例12: sendMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
private void sendMessage(String body, String toJid) {
    Log.i(TAG, "sendMessage()");
    Chat chat = ChatManager.getInstanceFor(mConnection).createChat(toJid, this);
    try {
        chat.sendMessage(body);
    } catch (SmackException.NotConnectedException | XMPPException e) {
        e.printStackTrace();
    }
}
 
開發者ID:meisterfuu,項目名稱:SmackAndroidDemo,代碼行數:10,代碼來源:SmackConnection.java

示例13: dispatch

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
@Override
public void dispatch(TavernaRun ignored, String messageSubject,
		String messageContent, String targetParameter) throws Exception {
	Chat chat = conn.getChatManager().createChat(targetParameter,
			new DroppingListener());
	Message m = new Message();
	m.addBody(null, messageContent);
	m.setSubject(messageSubject);
	chat.sendMessage(m);
}
 
開發者ID:apache,項目名稱:incubator-taverna-server,代碼行數:11,代碼來源:JabberDispatcher.java

示例14: sendBuffer

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
 * Send the contents of the cyclic buffer as an IM message.
 */
protected void sendBuffer() {
    try {
        final StringBuilder buf = new StringBuilder();

        final int len = cb.length();
        for (int i = 0; i < len; i++) {
            final LoggingEvent event = cb.get();
            buf.append(layout.format(event));
            // if layout doesn't handle exception, the appender has to do it
            if (layout.ignoresThrowable()) {
                final String[] s = event.getThrowableStrRep();
                if (s != null) {
                    for (int j = 0; j < s.length; j++) {
                        buf.append(Layout.LINE_SEP);
                        buf.append(s[j]);
                    }
                }
            }
        }

        if (chatroom) {
            groupchat.sendMessage(buf.toString());
        } else {
            final Iterator iter = chats.iterator();
            while (iter.hasNext()) {
                final Chat chat = (Chat) iter.next();
                chat.sendMessage(buf.toString());
            }
        }

    } catch (final Exception e) {
        errorHandler.error("Could not send message in IMAppender [" + name + "]", e, ErrorCode.GENERIC_FAILURE);
    }
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:38,代碼來源:IMAppender.java

示例15: sendChatMessage

import org.jivesoftware.smack.Chat; //導入方法依賴的package包/類
/**
 * Replies to IM clients via a chat message. The reply contains the invocation response as a string. 
 * @param msgCtx
 * @param responseMsg
 * @throws AxisFault
 */
private static void sendChatMessage(MessageContext msgCtx,String responseMsg) throws AxisFault {
		XMPPConnection xmppConnection = null;
		XMPPOutTransportInfo xmppOutTransportInfo = null;    		
		Message message = new Message();
    	
		xmppOutTransportInfo = (XMPPOutTransportInfo)msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
		if(xmppOutTransportInfo != null){
			message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
    		xmppConnection = xmppOutTransportInfo.getConnectionFactory().getXmppConnection();
        	if(xmppConnection == null){
        		handleException("Connection to XMPP Server is not established.");    		
        	}   	    		
		}else{
			handleException("Could not find message sender details.");
		}   			
		
		//initialize the chat manager using connection
		ChatManager chatManager = xmppConnection.getChatManager();
		Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);    		
		try{   			
		    message.setProperty(XMPPConstants.SEQUENCE_ID, 
		            xmppOutTransportInfo.getSequenceID());
			message.setBody(responseMsg);		
			chat.sendMessage(message);
			log.debug("Sent message :"+message.toXML());
		} catch (XMPPException e) {
			XMPPSender.handleException("Error occurred while sending the message : "+message.toXML(),e);
		}
    }
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:36,代碼來源:XMPPSender.java


注:本文中的org.jivesoftware.smack.Chat.sendMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。