通过Quickblox android sdk 2发送消息

时间:2014-09-08 13:59:14

标签: android quickblox

我已经尝试为android实现quickblox new api。 我有一个会话并启动了一个聊天实例而不是我正在尝试向特定ID发送消息。 使用下面的代码,我没有错误,但没有发送消息。感谢您的快速帮助

public void startNewChat(final ServerListener<Boolean> listener, Contact contact, String msg){
    QBPrivateChatManager manager = QBChatService.getInstance().getPrivateChatManager();

    QBPrivateChat chat = manager.createChat(Integer.parseInt(contact.getTripleD_user().getId()), new QBMessageListener<QBChat>() {

        @Override
        public void processError(String arg0, QBChatMessage arg1) {
            listener.getResult(false, arg0);

        }

        @Override
        public void processMessage(QBChat arg0, QBChatMessage arg1) {
            listener.getResult(true, null);

        }
    });
    try{

        chat.sendMessage(msg);          
    }
    catch(Exception e){
        listener.getResult(false, msg);
    }
}

1 个答案:

答案 0 :(得分:1)

试一试:

    private QBPrivateChat createChat(int opponentId) throws QBResponseException {
            boolean notNull = Utils.validateNotNull(privateChatManager);
            if (!notNull) {
                ErrorUtils.logError(TAG, " privateChatManager is NULL");
                throw new QBResponseException(context.getString(R.string.dlg_fail_create_chat));
            }
            QBPrivateChat privateChat = privateChatManager.getChat(opponentId);
            if (privateChat == null) {
                privateChat = privateChatManager.createChat(opponentId, privateChatMessageListener);
            }
            return privateChat;
    }

你的听众:

    private class PrivateChatMessageListener implements QBChatStateListener<QBPrivateChat> {

        @Override
        public void processMessage(QBPrivateChat privateChat, QBChatMessage chatMessage) {
            // do something
        } 
    }