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.

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 Xamarin Android Sample App

Download Xamarin iOS Sample App

Once you download the sample app, update the License Key and API Key in the MainActivity.cs file for Android and ViewController.cs file for iOS respectively(you can get these values from CometChat Admin Panel -> Settings -> API Key).

Please follow the steps mentioned in the README.md file to build and run the app.

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

All set to add CometChat to your Xamarin Android/iOS app ?? Just follow these steps and get the chat up and running in your app.

Add the SDK to your project

The first step is to add the NuGet packages for both Android/iOS.

For Android:
a. Expand the Android project.
b. Right-click on the packages folder and click on Add packages.
c. Search for Xamarin.Android.CometChat package and add it to your project.
d. Search for Xamarin.Android.CometChat.UI package and add it to your project.

For iOS:
a. Expand the iOS project.
b. Right-click on the packages folder and click on Add packages.
c. Search for Xamarin.iOS.CometChat package and add it to your project.
c. Search for Xamarin.iOS.CometChat.UI package and add it to your project.

Important

Make sure Multidex is enabled and Java heap size is set to 2G

Initialize the Chat

Once all the above steps are done, the first step to launch the Chat in your Xamarin application is to initialize the CometChat module. You need to use the below method to do so:

String siteurl = ""; 
String licenseKey = "COMETCHAT-XXXXX-XXXXX-XXXXX-XXXXX"; 
String apiKey = "xxxxxxxxxxxxxxxxxxxxxx"; 
Boolean isCometOnDemand = true;

CometChat cometChat = CometChat.GetInstance(this.ApplicationContext);

cometChat.InitializeCometChat(siteurl, licenseKey, apiKey, isCometOnDemand, new CometChatCallback((JSONObject obj) => {
   
   /*code block on success */
                        
},(JSONObject obj) => {
   
   /*code block on success */

}));

String siteurl = ""; 
String licenseKey = "COMETCHAT-XXXXX-XXXXX-XXXXX-XXXXX"; 
String apiKey = "xxxxxxxxxxxxxxxxxxxxxx"; 
Boolean isCometOnDemand = true;

cometchat = new CometChat();
readyUIFile = new readyUIFIle();
cometchat.InitializeCometChat(siteurl, licenseKey, apiKey, isCometOnDemand,(NSDictionary obj) =>{
if (obj != null){
       Console.WriteLine("Init Success " + obj.ToString());
  		/*code block on success*/
}
},(NSError obj) => {
if (obj != null)
{
       Console.WriteLine("Init Fail " + obj.ToString());
  			/*code block on fail*/
}
});

Log in 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.

String UID = "SUPERHERO1"

cometChat.LoginWithUID(this,UID, new CometChatCallback((JSONObject obj) => {
  /* code block for login success */                  
  
},(JSONObject obj) => {
  /* code block for login fail */

}));
String UID = "SUPERHERO1"

cometchat.loginWithUID(UID,(NSDictionary obj) => {
/*code block for login success*/

},(NSError obj) => {
/*code block for login failue*/

});

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. 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(activity, isFullScreen, new LaunchCallbacks(successObj => successCall(successObj), fail => failCall(fail), onChatroomInfo => ChatroomInfo(onChatroomInfo), onError => Error(onError), onLogout => Logout(onLogout), onMessageReceive => MessageReceive(onMessageReceive), onUserInfo => UserInfo(onUserInfo), onWindowClose => WindowClose(onWindowClose)));
readyUIFile = new readyUIFIle();

readyUIFile.LaunchCometChat(true, this, (userInfo) => OnUserInfo(userInfo),groupInfo=> OnGroupInfo(groupInfo),messageRecieve=>OnMessageRecieve(messageRecieve),launchSuccess=>OnLaunchSuccess(launchSuccess),launchFailure => OnLaunchFailure(launchFailure),onLogout => OnLogout(onLogout));

Please Note: You will have to implement the methods present in the LaunchCallbacks for Android. For iOS, you will have to implement all the methods passed as the parameters to the launchCometChat method.

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.

Please Note

If you are using iOS platform, please add the below five privacy permissions in the info.plist file which are necessary to access all the features. Please refer the image below.