QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms and devices. Check out our detailed guides to make integration easy and fast.

Quick Start

Learn how to run sample apps and send your first message.

QuickBlox SDK helps you implement a real-time chat, video chat, and push notifications to your app. You can fully concentrate on your mobile app development. Our SDK provides you with many helpful methods to build a chat app with diverse features.

This Quick Start page will help newcomers and even our veteran users familiarize themselves with basic SDK functionalities and logic. It lets you go through the easy steps of implementing QuickBlox in your app.

QuickBlox Android SDK supports both Java and Kotlin programming languages.

Before you begin

Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.

Start with sample apps

If you are just starting your app and developing it from scratch, we recommend to use our sample apps. Chat sample and Video chat sample are ready-to-go apps with appropriate functionality and simple enough that even novice developers will be able to understand them.

You can clone the repository using the link below:

git clone https://github.com/QuickBlox/quickblox-android-sdk.git

Chat code sample

To run the sample in Android Studio:

  1. Go to menu File => Open Project. (Or "Open an existing Project" if Android Studio is just opened)
  2. Select a path to the sample.
  3. Select Use default gradle wrapper (recommended) and click OK.
  4. Get application credentials and get Application ID, Authorization Key, Authorization Secret, and Account Key.
  5. Open App.kt (Kotlin sample) / App.java (Java sample)
    //src/main/java/com/quickblox/sample/chat/java/App.java
    and paste the credentials into the values of constants.
private static final String APPLICATION_ID = "";
private static final String AUTH_KEY = "";
private static final String AUTH_SECRET = "";
private static final String ACCOUNT_KEY = "";
private const val APPLICATION_ID = ""
private const val AUTH_KEY = ""
private const val AUTH_SECRET = ""
private const val ACCOUNT_KEY = ""
  1. Run the code sample.

Video chat sample

To run the sample in Android Studio:

  1. Go to menu File => Open Project. (Or "Open an existing Project" if Android Studio is just opened)
  2. Select a path to the sample.
  3. Select Use default gradle wrapper(recommended) and click OK.
  4. Get application credentials and get Application ID, Authorization Key, Authorization Secret, and Account Key.
  5. Open App.kt (Kotlin sample) / App.java (Java sample)
    //src/main/java/com/quickblox/sample/videochat/java/App.java
    and paste the credentials into the values of constants.
private static final String APPLICATION_ID = "";
private static final String AUTH_KEY = "";
private static final String AUTH_SECRET = "";
private static final String ACCOUNT_KEY = "";
private const val APPLICATION_ID = ""
private const val AUTH_KEY = ""
private const val AUTH_SECRET = ""
private const val ACCOUNT_KEY = ""
  1. Run the code sample.

Get application credentials

QuickBlox application includes everything that brings messaging right into your application - chat, video calling, users, push notifications, etc. To create a QuickBlox application, follow the steps below:

  1. Register a new account following this link. Type in your email and password to sign in. You can also sign in with your Google or Github accounts.
  2. Create the app clicking New app button.
  3. Configure the app. Type in the information about your organization into corresponding fields and click Add button.
  4. Go to Dashboard => YOUR_APP => Overview section and copy your Application ID, Authorization Key, Authorization Secret, and Account Key .

Requirements

The minimum requirements for QuickBlox Android SDK are:

  • Android 5.0 (API 21).
  • Android Studio.
  • Gradle 4.6.
  • Gradle plugin 2.5.1.

Install QuickBlox SDK into your app

To connect QuickBlox SDK to your app, import QuickBlox SDK dependencies via build.gradle file.

Include reference to SDK repository in your project-level build.gradle file at the root directory. Specify the URL of QuickBlox repository where the files are stored. Following this URL gradle finds SDK artifacts.

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
        }
    }
}

def qbSdkVersion = '3.9.2'

When the artifacts are found in QuickBlox repository, they get imported to particular SDK modules in build.gradle project file. Add the following code lines to app-level build.gradle file.

dependencies {
    implementation "com.quickblox:quickblox-android-sdk-messages:3.9.2"
    implementation "com.quickblox:quickblox-android-sdk-chat:3.9.2"
    implementation "com.quickblox:quickblox-android-sdk-content:3.9.2"
    implementation "com.quickblox:quickblox-android-sdk-videochat-webrtc:3.9.2"
    implementation "com.quickblox:quickblox-android-sdk-conference:3.9.2"
    implementation "com.quickblox:quickblox-android-sdk-customobjects:3.9.2"
}

Send your first message

Initialize QuickBlox SDK

Initialize the framework with your application credentials. Pass APPLICATION_ID, AUTH_KEY, AUTH_SECRET, and ACCOUNT_KEY to the init() method.

🚧

Pay attention

You must initialize SDK before calling any methods through the SDK, except for the init() method. If you attempt to call a method without connecting, the error is returned.

static final String APPLICATION_ID = "41";
static final String AUTH_KEY = "lkjdueksu7392kj";
static final String AUTH_SECRET = "iiohfdija792hj";
static final String ACCOUNT_KEY = "sdjfnksnlk2bk1k34kb";
//
QBSettings.getInstance().init(getApplicationContext(), APPLICATION_ID, AUTH_KEY, AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
private const val APPLICATION_ID = "41"
private const val AUTH_KEY = "lkjdueksu7392kj"
private const val AUTH_SECRET = "iiohfdija792hj"
private const val ACCOUNT_KEY = "sdjfnksnlk2bk1k34kb"
//
QBSettings.getInstance().init(applicationContext, APPLICATION_ID, AUTH_KEY, AUTH_SECRET)
QBSettings.getInstance().accountKey = ACCOUNT_KEY

Authorize user

In order to use the abilities of QuickBlox SDK, you need to authorize your app on the QuickBlox server, log in to your account and create a session. To get it all done call the signIn() method and pass instance of QBUser with defined login and password to it using the code snippet below.

📘

Note

To login with a user, you need login (or email) and password only. Other fields are optional (full name, phone, external ID, etc).

final QBUser user = new QBUser();
user.setLogin("MyLogin");
user.setPassword("mypassword");

QBUsers.signIn(user).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser user, Bundle args) {
        
    }

    @Override
    public void onError(QBResponseException error) {
        
    }
});
val user = QBUser()
user.login = "MyLogin"
user.password = "mypassword"

QBUsers.signIn(user).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(user: QBUser?, args: Bundle?) {
        
    }

    override fun onError(error: QBResponseException?) {
        
    }
})

Connect to Chat

Having connected to QuickBlox server and authorized with a user, you can proceed with connecting to Chat server to start using Chat module functionality. Call the login() method to connect to Chat server.

QBChatService.getInstance().login(qbUser, new QBEntityCallback() {
    @Override
    public void onSuccess(Void o, Bundle bundle) {
 
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBChatService.getInstance().login(qbUser, object : QBEntityCallback<Void> {
    override fun onSuccess(o: Void?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Create dialog

QuickBlox provides three types of dialogs: 1-1 dialog, group dialog, and public dialog. Learn more about dialogs here.

Specify occupantIdsList within ArrayList. Create a QBChatDialog instance and specify QBdialogueType via dialog.setType parameter. Specify occupantsIds from the ArrayList to add participants of the dialog being created. Once the instance is created, pass it by calling the createChatDialog() method.

ArrayList<Integer> occupantIdsList = new ArrayList<Integer>();
occupantIdsList.add(123);
 
QBChatDialog dialog = new QBChatDialog();
dialog.setType(QBDialogType.PRIVATE);
dialog.setOccupantsIds(occupantIdsList);
 
// or just use DialogUtils
//QBChatDialog dialog = DialogUtils.buildPrivateDialog(recipientId);
 
QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback<QBChatDialog>() {
    @Override
    public void onSuccess(QBChatDialog result, Bundle params) {
 
    }
 
    @Override
    public void onError(QBResponseException responseException) {
 
    }
});
val occupantIdsList = ArrayList<Int>()
occupantIdsList.add(123)

val dialog = QBChatDialog()
dialog.type = QBDialogType.PRIVATE
dialog.setOccupantsIds(occupantIdsList)

// or just use DialogUtils
//QBChatDialog dialog = DialogUtils.buildPrivateDialog(recipientId);

QBRestChatService.createChatDialog(dialog).performAsync(object : QBEntityCallback<QBChatDialog> {
    override fun onSuccess(result: QBChatDialog?, params: Bundle?) {

    }

    override fun onError(responseException: QBResponseException?) {

    }
})

Subscribe to receive messages

Through QBDialogMessageListener you can monitor whether an incoming message or error is received from QuickBlox server. Use QBIncomingMessagesManager to listen to all incoming messages and related errors.

QBChatService chatService = QBChatService.getInstance();
QBIncomingMessagesManager incomingMessagesManager = chatService.getIncomingMessagesManager();

incomingMessagesManager.addDialogMessageListener(new QBChatDialogMessageListener() {
    @Override
    public void processMessage(String dialogID, QBChatMessage qbChatMessage, Integer senderID) {

    }

    @Override
    public void processError(String dialogID, QBChatException e, QBChatMessage qbChatMessage, Integer senderID) {

    }
});
val chatService = QBChatService.getInstance()
val incomingMessagesManager = chatService.incomingMessagesManager

incomingMessagesManager.addDialogMessageListener(object : QBChatDialogMessageListener {
    override fun processMessage(dialogID: String?, qbChatMessage: QBChatMessage?, senderID: Int?) {

    }

    override fun processError(dialogID: String?, e: QBChatException?, qbChatMessage: QBChatMessage?, senderID: Int?) {

    }
})

Join Dialog and Send message

Before sending a message you should join the dialog you created by using:

DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(0);
dialog.join(history, new QBEntityCallback() {
    @Override
    public void onSuccess(Object o, Bundle bundle) {
    }

    @Override
    public void onError(QBResponseException e) {
    }
});
val history = DiscussionHistory()
history.maxStanzas = 0
dialog.join(history, object : QBEntityCallback<Void> {
    override fun onSuccess(o: Void?, bundle: Bundle?) {
    }

    override fun onError(e: QBResponseException?) {
    }
})

To send a message, create QBChatMessage instance and specify a text message via chatMessage.setBody parameter. Then, call the sendMessage() method and pass QBChatMessage instance within it.

QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setBody("Hello QuickBlox!");

dialog.sendMessage(chatMessage, new QBEntityCallback<Void>() {
    @Override
    public void onSuccess(Void aVoid, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val chatMessage = QBChatMessage()
chatMessage.body = "Hello QuickBlox!"

dialog.sendMessage(chatMessage, object : QBEntityCallback<Void> {
    override fun onSuccess(aVoid: Void?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Updated 2 days ago


What's Next

Setup

Quick Start


Learn how to run sample apps and send your first message.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.