登入聊天

使用使用者建立會話並登入 QuickBlox 聊天

// Initialise Chat service
QBChatService chatService = QBChatService.getInstance();
 
final QBUser user = new QBUser("garrysantos", "garrysantospass");
QBAuth.createSession(user, new QBEntityCallback<QBSession>() {
    @Override
    public void onSuccess(QBSession session, Bundle params) {
        // success, login to chat
 
        user.setId(session.getUserId());
 
        chatService.login(qbUser, new QBEntityCallback() {
            @Override
            public void onSuccess() {
 
            }
 
            @Override
            public void onError(QBResponseException errors) {
 
            }
        });
    }
 
    @Override
    public void onError(QBResponseException errors) {
 
    }
});

要處理不同的連線狀態,請使用 ConnectionListener:

ConnectionListener connectionListener = new ConnectionListener() {
    @Override
    public void connected(XMPPConnection connection) {
 
    }
 
    @Override
    public void authenticated(XMPPConnection connection) {
 
    }
 
    @Override
    public void connectionClosed() {
 
    }
 
    @Override
    public void connectionClosedOnError(Exception e) {
        // connection closed on error. It will be established soon
    }
 
    @Override
    public void reconnectingIn(int seconds) {
 
    }
 
    @Override
    public void reconnectionSuccessful() {
 
    }
 
    @Override
    public void reconnectionFailed(Exception e) {
 
    }
};
 
QBChatService.getInstance().addConnectionListener(connectionListener);