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    

To add CometChat to your Android app, please perform the following.

Update Your Gradle File

Add the below lines in Project level build.gradle file in repositories section

repositories {
    maven{
            url 'https://dl.bintray.com/cometchat/CometChat'
        }
}

Add Dependencies

Add the below dependencies in Module level build.gradle file in dependencies section

dependencies {
    compile 'com.inscripts:CometChat:7.4.+'
    compile 'com.inscripts:CometChatUI:7.4.+'
}

Enable Multidex

To enable Multidex please add the following line to the defaultConfig element of the build.gradle file of your application. To know more about Multidex applications and why it is necessary, please click here.

Also, add the dexOptions and the packagingOptions sections as shown below

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'
    }

Disable Instant Run

Please make sure that the Instant Run feature of Android Studio is disabled. To disable the same, please follow the below mentioned steps:

1.Go to Settings in Android Studio
2.Navigate to Build, Execution, Deployment > Instant Run.
3.Disable the Instant Run Feature.

Initialize the SDK

Initialization binds the SDK to your app and syncs the various basic parameters required for the CometChat SDK to function.

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

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

Important

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.

Setup