当前位置: 首页>>代码示例>>Java>>正文


Java ChatManager类代码示例

本文整理汇总了Java中org.jivesoftware.smack.ChatManager的典型用法代码示例。如果您正苦于以下问题:Java ChatManager类的具体用法?Java ChatManager怎么用?Java ChatManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChatManager类属于org.jivesoftware.smack包,在下文中一共展示了ChatManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import org.jivesoftware.smack.ChatManager; //导入依赖的package包/类
public void send(final IMessage message) throws NotificationException {
  XMPPConnection connection = null;
  try {
    connection = createConnection();
    final ChatManager chatManager = connection.getChatManager();
    for (final String body : this.bodies) {
      send(chatManager, body, message);
    }
  } catch (final XMPPException exception) {
    logger.log(ILevel.ERROR, exception.getMessage(), exception);
    throw new NotificationException("Coudn't send notification. " + toString(message), exception); //$NON-NLS-1$
  } finally {
    if (connection != null) {
      connection.disconnect();
    }
  }
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:18,代码来源:MessageSender.java

示例2: getChat

import org.jivesoftware.smack.ChatManager; //导入依赖的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;
}
 
开发者ID:tesfaye,项目名称:LOL-Chat,代码行数:17,代码来源:Friend.java

示例3: initState

import org.jivesoftware.smack.ChatManager; //导入依赖的package包/类
private void initState() {
    getSupportActionBar().setTitle(XMPPManager.getInstance().getState().getMessage());
    chatManager = ChatManager.getInstanceFor(XMPPManager.getInstance().connection);
    chatManager.addChatListener(new ChatManagerListener() {
        @Override
        public void chatCreated(Chat chat, boolean createdLocally) {
            if (createdLocally) {
               // Chat created by myself
            } else {
               // Chat created by others
                chat.addMessageListener(chatMessageListener);
            }

        }
    });

    if (!TextUtils.isEmpty(username)) {
        chat = chatManager.createChat(username + "@" + XMPPManager.serverName, chatMessageListener);
    }

}
 
开发者ID:gongmingqm10,项目名称:SmackDemo,代码行数:22,代码来源:MainActivity.java

示例4: 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);
	}

}
 
开发者ID:ControlAltDieliet,项目名称:system_updater,代码行数:21,代码来源:Bot.java

示例5: sendMessage

import org.jivesoftware.smack.ChatManager; //导入依赖的package包/类
/**
 * <p>sendMessage</p>
 *
 * @param xmppTo a {@link java.lang.String} object.
 * @param xmppMessage a {@link java.lang.String} object.
 * @return a boolean.
 */
public boolean sendMessage(String xmppTo, String xmppMessage) {
    if (!isLoggedIn()) {
        connectToServer();
    }
	try {
	    ChatManager cm = xmpp.getChatManager();
		cm.createChat(xmppTo, new NullMessageListener()).sendMessage(xmppMessage);
		log().debug("XMPP Manager sent message to: " + xmppTo);
	} catch (XMPPException e) {
		log().fatal("XMPP Exception Sending message ", e);
		return false;
	}

	return true;

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:24,代码来源:XMPPNotificationManager.java

示例6: 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;
}
 
开发者ID:FanHuaRan,项目名称:SmackStudy,代码行数:15,代码来源:XMPPUtil.java

示例7: 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;
}
 
开发者ID:FanHuaRan,项目名称:SmackStudy,代码行数:15,代码来源:XMPPUtil.java

示例8: initXMPP

import org.jivesoftware.smack.ChatManager; //导入依赖的package包/类
/**
 * 初始化XMPP
 */
void initXMPP() {
	mXMPPConnection = mXmppConnectionManager.init();						//初始化XMPPConnection
	loginXMPP();															//登录XMPP
	ChatManager chatmanager = mXMPPConnection.getChatManager();
	chatmanager.addChatListener(new ChatManagerListener() {
		@Override
		public void chatCreated(Chat arg0, boolean arg1) {
			arg0.addMessageListener(new MsgListener(MsfService.this, mNotificationManager));
		}
	});
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:15,代码来源:MsfService.java

示例9: 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", "发送成功");
	}
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:19,代码来源:XmppUtil.java

示例10: sendMessage

import org.jivesoftware.smack.ChatManager; //导入依赖的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

示例11: 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);
		}
    }
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:36,代码来源:XMPPSender.java

示例12: 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());

}
 
开发者ID:ppapapetrou76,项目名称:sonar-xmpp-notifications,代码行数:14,代码来源:XMPPAdapter.java

示例13: shouldSendMessage

import org.jivesoftware.smack.ChatManager; //导入依赖的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());
}
 
开发者ID:ppapapetrou76,项目名称:sonar-xmpp-notifications,代码行数:13,代码来源:XMPPAdapterTest.java

示例14: connect

import org.jivesoftware.smack.ChatManager; //导入依赖的package包/类
public void connect() {
	try {

		ConnectionConfiguration config = new ConnectionConfiguration(server, 5222);
		config.setCompressionEnabled(true);
		config.setSASLAuthenticationEnabled(true);
		config.setReconnectionAllowed(true);
		
		
		connection = new XMPPConnection(config);

		connection.connect();

		connection.login(username, password);

		final ChatManager chatManager = connection.getChatManager();
		chatManager.addChatListener(new ChatManagerListener() {

			@Override
			public void chatCreated(Chat chat, boolean createdLocally) {
				chat.addMessageListener(getMessageListener());

			}
		});
	} catch (XMPPException e) {

		throw new RuntimeException(e);
	}
}
 
开发者ID:jackhatedance,项目名称:visual-programming,代码行数:30,代码来源:XmppAgent.java

示例15: 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);
	}
 
开发者ID:jackhatedance,项目名称:visual-programming,代码行数:34,代码来源:XmppAgent.java


注:本文中的org.jivesoftware.smack.ChatManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。