2015-10-08 61 views
0

我在我的Android應用程序中使用Quickblox SDK。Quickblox - QBMessageListener永遠不會進入processMessage()

我可以在QBPrivateChat中發送消息,我可以毫無問題地獲取它們。

我向QBPrivateChat添加了一個QBMessageListener,以便在聊天的其他用戶發送新消息時立即收到通知。

final QBMessageListener<QBPrivateChat> messageListener = new QBMessageListener<QBPrivateChat>() { 

    @Override 
    public void processMessage(QBPrivateChat privateChat, QBChatMessage chatMessage) { 
     Log.e(TAG, "privateChatMessageListener - processMessage"); 
    } 

    @Override 
    public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage) { 
     Log.e(TAG, "privateChatMessageListener - processError"); 
    } 

}; 

QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager(); 
privateChatManager.addPrivateChatManagerListener(new QBPrivateChatManagerListener() { 

    @Override 
    public void chatCreated(QBPrivateChat privateChat, boolean createdLocally) { 
     Log.e(TAG, "QBPrivateChatManagerListener - chatCreated"); 

     if(!createdLocally) 
      privateChat.addMessageListener(privateChatMessageListener); 
    } 

}); 

Integer opponentId = 1234; 

QBPrivateChat privateChat = privateChatManager.getChat(opponentId); 

if (privateChat == null) 
    privateChat = privateChatManager.createChat(opponentId, messageListener); 
else 
    privateChat.addMessageListener(messageListener); 

問題是,應用程序永遠不會經歷processMessage/processError。我試圖找出幾個小時沒有成功。

有人可以告訴我我做錯了什麼嗎?

預先感謝您

回答

0

這裏的正確方法是做

if (privateChat == null){ 
    privateChat = privateChatManager.createChat(opponentId, messageListener); 
    privateChat.addMessageListener(messageListener); 
}else{ 
} 
相關問題