当前位置: 首页>>代码示例>>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;未经允许,请勿转载。