本文整理汇总了Java中org.jivesoftware.smack.ChatManager.createChat方法的典型用法代码示例。如果您正苦于以下问题:Java ChatManager.createChat方法的具体用法?Java ChatManager.createChat怎么用?Java ChatManager.createChat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.ChatManager
的用法示例。
在下文中一共展示了ChatManager.createChat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import org.jivesoftware.smack.ChatManager; //导入方法依赖的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);
}
}
示例2: createChat
import org.jivesoftware.smack.ChatManager; //导入方法依赖的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;
}
示例3: createChat
import org.jivesoftware.smack.ChatManager; //导入方法依赖的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: sendMessage
import org.jivesoftware.smack.ChatManager; //导入方法依赖的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", "发送成功");
}
}
示例5: sendChatMessage
import org.jivesoftware.smack.ChatManager; //导入方法依赖的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);
}
}
示例6: sendMessage
import org.jivesoftware.smack.ChatManager; //导入方法依赖的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());
}
示例7: send
import org.jivesoftware.smack.ChatManager; //导入方法依赖的package包/类
public void send(String receiverAddress, Message msg) throws XMPPException {
if (msg.messageType == MessageType.SyncRequest)
setBlockedOutgoingRequest(receiverAddress, msg);
ChatManager chatManager = connection.getChatManager();
Chat chat = chatManager.createChat(receiverAddress,
getMessageListener());
// TODO convert body to hierarchical text
String msgBody = "";
if (msg.body != null) {
if (msg.body.getType() == ObjectType.NORMAL) {
for (int i = 0; i < msg.body.getFieldCount(); i++) {
if (i != 0)
msgBody += ";";
_Object param = msg.body.getField(i).getTarget();
msgBody += param.getName() + ":" + param.getValue();
}
} else if (msg.body.getType().isValueObject()) {
msgBody = msg.body.getValue();
}
}
// String response = String.format("[%s] %s", msg.getSubject(),
// msgBody);
chat.sendMessage(msgBody);
}
示例8: send
import org.jivesoftware.smack.ChatManager; //导入方法依赖的package包/类
private void send(final ChatManager chatManager, final String body, final IMessage message) throws XMPPException {
final Chat chat = chatManager.createChat(body, new DeafMessageListener());
chat.sendMessage(toString(message));
}
示例9: getUserResponse
import org.jivesoftware.smack.ChatManager; //导入方法依赖的package包/类
/**
* Read the PIN number sent by the user as the reply.
*
* @param connection
* @param userName
* @return
*/
public boolean getUserResponse(XMPPConnection connection, String userName) {
String response = null;
Presence presence = connection.getRoster().getPresence(userName);
if (presence.isAvailable()) {
try {
ChatManager chatManager = connection.getChatManager();
Chat chat = chatManager.createChat(userName, null);
PacketFilter filter =
new AndFilter(new PacketTypeFilter(Message.class), new FromContainsFilter(userName));
XmppResponseListener chatListener = new XmppResponseListener();
connection.addPacketListener(chatListener, filter);
if (isPINEnabled) {
chat.sendMessage("Please reply with your PIN Number here.");
if (log.isInfoEnabled()) {
log.info("User PIN is sent to the user and awaiting for the response.");
}
while (!chatListener.isResponseReceived()) {
Thread.sleep(100);
}
response = chatListener.getResponse();
if (response != null) {
return userPIN.contentEquals(response.trim());
}
} else {
chat.sendMessage(
"You are about to get authenticated for your OpenID. Do you want to continue: [Yes] or [No]");
if (log.isInfoEnabled()) {
log.info("User PIN is sent to the user and awaiting for the response.");
}
while (!chatListener.isResponseReceived()) {
Thread.sleep(100);
}
response = chatListener.getResponse();
if (response != null) {
if ("YES".equalsIgnoreCase(response.trim())) {
return true;
} else if ("NO".equalsIgnoreCase(response.trim())) {
return false;
} else {
pinDisabledResponse = false;
return false;
}
}
}
} catch (Exception e) {
log.error("Error while getting user response", e);
}
} else {
return false;
}
return false;
}