本文整理汇总了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");
}
}
示例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);
}
}
示例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();
}
示例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");
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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", "发送成功");
}
}
示例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);
}
}
示例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 );
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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);
}
}