我在Android应用中使用Quickblox SDK。
我可以在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);
问题是app永远不会经历processMessage / processError。我试着弄清楚几个小时没有成功。
有人可以告诉我我做错了吗?
提前谢谢
答案 0 :(得分:0)
这里正确的方法是
if (privateChat == null){
privateChat = privateChatManager.createChat(opponentId, messageListener);
privateChat.addMessageListener(messageListener);
}else{
}