2012-03-26 105 views
1

我想使用Android的smack API來開發一個使用Gmail帳戶的聊天室。我設法創建了一個房間並向羣組發送消息。但是當有人回覆我無法直接在聊天窗口或通過程序(muc.addMessageListener(myMessageListener)和PacketListener)接收傳入消息時。無法接收聊天消息使用smackx MultiUserChat API

 


    ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); 
    config.setSASLAuthenticationEnabled(true); 
    connection = new XMPPConnection(config); 
    connection.connect(); 
    connection.login("[email protected]", "password"); 
    muc = new MultiUserChat(connection, "[email protected]le.com"); 
    muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT)); 
    muc.join("kandroid6990"); 
    muc.invite("[email protected]/User1", "Welcome!"); 
    muc.invite("[email protected]/User2", "Welcome!"); 

 


    Message msg = new Message("[email protected]le.com", Message.Type.groupchat); 
    msg.addBody(Message.getDefaultLanguage(), messageText); 
    muc.sendMessage(msg); 

 
+0

你通過得到你的答案 – Lokesh 2014-10-18 17:11:05

回答

2

嘗試

muc.addMessageListener(myMessageListener); 
+0

在我的問題程序引用muc.addMessageListener(myMessageListener); 和PacketListeners – kamaraj6990 2012-03-29 04:40:15

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    
    } 
    }); 
    } 
0

試試這個,它可以幫助在收到羣組聊天消息 只實現羣聊聽衆

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


      } 
     } 
    } 
}, filter); 
+0

in smack 4.1.5 MessageTypeFilter是私人訪問,所以我們不能實現這個 – rajeesh 2016-01-21 08:55:08