Skip to main content

Before you begin

  1. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  2. Configure QuickBlox SDK for your app. Check out Setup page for more details.
  3. Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
Visit Key Concepts page to learn the most important QuickBlox concepts.

Connect to chat server

To connect to the chat server use the code snippet below.

Connect to chat server with QuickBlox session token

In case, you authenticate with QuickBlox via Firebase, Facebook, or Custom Identity Provider, you should connect to the chat server with QuickBlox user session token and QuickBlox user ID. As a result of successful authentication via Firebase, Facebook, or Custom Identity Provider, you receive a QuickBlox user session token and QuickBlox user ID. Use QuickBlox user session token as a password and QuickBlox user ID as a login to connect to the chat server.
Don’t use the Firebase/Facebook access token as a password to connect to the chat server.You will receive the following runtime error in this case:
The login method accepts a user argument with the following fields:

Subscribe to connection state

Subscribe to the connection state changes using the following code snippet.

Check if connected to chat server

Check the connection state using the following code snippet.

Disconnect from chat server

Disconnect from the chat server using the snippet below.

Enable auto-reconnect to chat

The SDK reconnects automatically when the connection to the chat server is lost. There is a way to disable it and then manage it manually.

Manage chat connections

To provide a seamless chat experience, our SDK manages connections to the chat server at an application-wide level. Thus, when your application goes background, you should disconnect from the chat server to be able to receive offline messages. When your application goes foreground, you should connect to the chat server to become online and start sending and receiving messages. Use androidx.lifecycle.LifecycleObserver to determine when the application goes background.
Make sure to add an instance of the created lifecycle observer class to the androidx.lifecycle.ProcessLifecycleOwner() to process lifecycle changes within your app.

Set connection settings

Use the settings below to configure the connection to the chat server.