在Chatblox Chat sdk聊天/ 1:1聊天

时间:2015-02-04 12:18:06

标签: android quickblox

如何在两个用户之间的quickblox私聊中获得离线和在线用户。 如果两个用户Jone和kally如果kally离线而不是如何获取离线用户的状态Kally我的代码在这里。请检查并帮助我。

         try {
            QBChatMessage chatMessage = new QBChatMessage();
            chatMessage.setBody(inputbox.getText().toString()); 
            chatMessage.setProperty("save_to_history", "1"); 
            long time = System.currentTimeMillis()/1000;
            chatMessage.setProperty("date_sent", time + "");
            privateChat.sendMessage(chatMessage);
            showMessage(chatMessage);
            inputbox.setText("");
        } catch (XMPPException e) {
            Log.e("XMPPException",e.toString());
        } catch (SmackException.NotConnectedException e) {
            Log.e("Not Connected Exception",e.toString());
        }catch (NullPointerException e) {
            Log.e("NullPointerException", e.toString());
        }catch (Exception e) {
            Log.e("Exception", e.toString());
        }

       QBPrivateChatManagerListener privateChatManagerListener = new              QBPrivateChatManagerListener() {
    @Override
    public void chatCreated(final QBPrivateChat privateChat, final boolean createdLocally) {
        if(!createdLocally){
            privateChat.addMessageListener(privateChatMessageListener);
        }
    }
};

QBMessageListener<QBPrivateChat> privateChatMessageListener = new QBMessageListener<QBPrivateChat>() {
    @Override
    public void processMessage(QBPrivateChat privateChat, final QBChatMessage chatMessage) {
        Log.w(Tag, "new incoming message: chatMessage" + chatMessage);
        showMessage(chatMessage);
        playBeepSound(mContext);
    }

    @Override
    public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage){
        Log.w(Tag, "new incoming message: originMessage" + originMessage);
    }

    @Override
    public void processMessageDelivered(QBPrivateChat privateChat, String messageID){
        Log.w(Tag, "new incoming message:messageID " + messageID);
    }

    @Override
    public void processMessageRead(QBPrivateChat privateChat, String messageID){
        Log.w(Tag, "new incoming message:messageID messageID" + messageID);
    }
};
private void createNewDialog(){
    privateChatManager = QBChatService.getInstance().getPrivateChatManager();
    privateChatManager.createDialog(opponentId, new QBEntityCallbackImpl<QBDialog>() {
        @Override
        public void onSuccess(QBDialog dialog, Bundle args) {
            //Log.e("QBdialog", ""+dialog);
            //Log.e("id", dialog.getDialogId());
            setUpListener();
            isQBDialog = true;
        }

        @Override
        public void onError(List<String> errors) {
            Log.e("errors", ""+errors);
            isQBDialog = false;

        }
    });
}

private void setUpListener(){
privateChatManager.addPrivateChatManagerListener(privateChatManagerListener);
    privateChat = privateChatManager.getChat(opponentId);
    if (privateChat == null) {
        privateChat = privateChatManager.createChat(opponentId, privateChatMessageListener);
        privateChat.addIsTypingListener(privateChatIsTypingListener);

    }else{
        privateChat.addMessageListener(privateChatMessageListener);
        privateChat.addIsTypingListener(privateChatIsTypingListener);
    }
}

我正在关注聊天链接 http://quickblox.com/developers/Android_XMPP_Chat_Sample

2 个答案:

答案 0 :(得分:0)

我还试图在一对一聊天中实现quickblox聊天,然后我因为文档不够而陷入困境。然后我找到了socket.io,这对于一对一聊天更方便。点击链接:http://socket.io/blog/native-socket-io-and-android/。您还必须找到一个免费的node.js托管公司。我可以建议你使用heroku.com

答案 1 :(得分:0)

您可以添加用于跟踪用户状态的侦听器 - RosterListener。

例如:

https://github.com/QuickBlox/q-municate-android/blob/master/Q-municate_core/src/main/java/com/quickblox/q_municate_core/qb/helpers/QBFriendListHelper.java

Q-municate实时跟踪用户状态(私人聊天和群聊)。