无法使用smackx MultiUserChat API接收聊天消息

时间:2012-03-26 19:09:37

标签: android xmpp chat openfire smack

我正在尝试使用smack API for Android来开发使用Gmail帐户的聊天室。我设法创建了一个房间并向群组发送消息。但是,当有人回复时,我无法直接在聊天窗口或通过程序(muc.addMessageListener(myMessageListener)和PacketListener)接收传入消息。



    ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
    config.setSASLAuthenticationEnabled(true);
    connection = new XMPPConnection(config);
    connection.connect();
    connection.login("kandroid6990@gmail.com", "password");
    muc = new MultiUserChat(connection, "private-chat-12325669-dead-beff-feed-fedcba987454@groupchat.google.com");
    muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
    muc.join("kandroid6990");
    muc.invite("karthikbaskar3@gmail.com/User1", "Welcome!");
    muc.invite("kamaraj6990@gmail.com/User2", "Welcome!");




    Message msg = new Message("private-chat-12325669-dead-beff-feed-fedcba987454@groupchat.google.com", Message.Type.groupchat);
    msg.addBody(Message.getDefaultLanguage(), messageText);
    muc.sendMessage(msg);


3 个答案:

答案 0 :(得分:2)

尝试

muc.addMessageListener(myMessageListener);

答案 1 :(得分:0)

private MultiUserChat   muc; /* Initialize muc */
private void listeningForMessages() 
 {
    muc.addMessageListener(new PacketListener() {
    public void processPacket(Packet packet) 
    {
        final Message message = (Message) packet;
        // Do your action with the message              
    }
    });
  }

答案 2 :(得分:0)

试试这可能有助于接收群聊信息 只需实现组聊天监听器

PacketFilter filter = new MessageTypeFilter(Message.Type.groupchat);
XmppTool.con.addPacketListener(new PacketListener() {
    @Override
    public void processPacket(Packet packet) {
        Message message = (Message) packet;


            }
        }
    }
}, filter);