CometChat Developer Documentation

Welcome Ninja!

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Get Started    

Quick Start

The simplest voice, video and text chat SDK for your Android app.

CometChat enables you to add voice, video and text chat to your Android app in minutes! That's not all, CometChat has whiteboard, writeboard, real-time translation and more.

First, try out our sample chat app!

Before you add CometChat to your app, go ahead and download our sample app from GitHub. It gives you an indication of what to expect from CometChat.

Download Sample App

Once you download the sample app, update the License Key and API Key in the MainActivity.java class in the project.(you can get these values from CometChat Admin Panel -> Settings -> API Key).

Once these changes are done, please build and run the app.

Next, use these steps to quickly add CometChat to your app

All set to add CometChat to your Android app? Just follow these steps and get CometChat up and running in your app.

Add the SDK to your project

  1. Add the below code to the project level build.gradle file of your project under the repositories section.
repositories {
    maven{
            url 'https://dl.bintray.com/cometchat/CometChat'
        }
}
  1. Add the below dependencies to the app level build.gradle file.
dependencies {
    compile 'com.inscripts:CometChat:7.4.+'
    compile 'com.inscripts:CometChatUI:7.4.+'
}
  1. Enable Multidex for your app and add the dexOptions and packagingOptions in the app level build.gradle file.
multiDexEnabled true

dexOptions {
    javaMaxHeapSize "2048M"
    }

    packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    }

Instant Run

Please make sure that the Instant Run feature of the Android Studio is disabled.

Initialize the Chat

The first step to launch the Chat in your Android application is to initialize the CometChat module. You need to use the below method to do so:

private String licenseKey = "COMETCHAT-XXXXX-XXXXX-XXXXX-XXXXX"
private String apiKey = "xxxxxxxxxxxxxxxxxxxxxx";

CometChat cometChat = CometChat.getInstance(context);
cometChat.initializeCometChat("", licenseKey, apiKey, true, new Callbacks() {
	@Override
	public void successCallback(JSONObject jsonObject) {
  
  }
	@Override
	public void failCallback(JSONObject jsonObject) {
  
  }
});

The licenseKey and apiKey is available at CometChat Admin Panel -> Settings -> API Key.

Login To Chat

The next step to launch the chat is to log in the user. CometChat provides a method loginWithUID() to log the user into chat. We have already added 5 demo users to your account with the UIDs SUPERHERO1,SUPERHERO2,SUPERHERO3,SUPERHERO4 and SUPERHERO5. You can use any of the users to log in. If you would like more information regarding User management, you can get it here.

private String UID = "SUPERHERO1";

cometChat.loginWithUID(context,UID, new Callbacks() {
  @Override
  public void successCallback(JSONObject jsonObject) {
  
  }
  @Override
  public void failCallback(JSONObject jsonObject) {
  
  }
});)

Keep in mind

The initializeCometChat() must only be called once in the entire scope of the app. We suggest, you call the initializeCometChat method on app startup preferably in the onCreate() method of the Application class. The loginWithUID() method ideally should be called once the user successfully logs in to your application.

Launch Chat

In order to launch the chat, you need to use the launchCometChat() method.

boolean isFullScreen = true;
cometChat.launchCometChat(context, isFullScreen, new LaunchCallbacks() {
                    @Override
                    public void successCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void failCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void userInfoCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void chatroomInfoCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void onMessageReceive(JSONObject jsonObject) {

                    }

                    @Override
                    public void onWindowClose(JSONObject jsonObject) {

                    }

                    @Override
                    public void onLogout() {

                    }
                });

CometChat also provides you with other options such as launch the chat window for a particular user directly or for a particular group. For more information, please check here.

You're all set! Go ahead and explore

Now that you have CometChat running in your app, you can tweak it further. Explore the other sections to learn more.

Quick Start

The simplest voice, video and text chat SDK for your Android app.