Android Quickstart

This Quickstart guide will help you get started with ChatCamp on Android quickly!

ChatCamp enables you to add chat into your Android app quickly and efficiently. Our Android SDK provides you with ready-to-use native functions and code snippets to integrate chat quickly. This guide will help you in setting up chat into your app.

Setup for Android

1. Create a new application from ChatCamp Dashboard

You need to create a new ChatCamp application to start integrating chat SDK into your Android app. The application may be created by going to our ChatCamp Dashboard.

2. Install ChatCamp SDK

Now you need to add our ChatCamp SDK into your Android project. To add our chat SDK include the following lines into your app build.grade file.

repositories {
	maven { url "https://raw.githubusercontent.com/ChatCamp/ChatCamp-Android-SDK/master/" }
}

dependencies {
	implementation 'io.chatcamp.sdk:chatcamp-android-sdk:0.1.10'
}

3. Initialize ChatCamp SDK

Our chat messaging SDK needs to be initialized only once. You may do so preferably in onCreate function of your main activity.

ChatCamp.init(this, APP_ID);

Here APP_ID is the ChatCamp application ID which you obtained from ChatCamp Dashboard.

4. Connect to ChatCamp backend

To connect to our chat backend you would need to use our connect function. It automatically creates the user if the user doesn't exist. We offer authentication via access token as well. This is discussed later in the guide.

ChatCamp.connect(USER_ID, new ChatCamp.ConnectListener() {
  @Override
  public void onConnected(User user, ChatCampException e) {
    //You are connected to ChatCamp backend now.
  }
                        
 });

Here USER_ID is the ID of your current app user.

5. Set display name of the user

You may set username by calling updateUserDisplayName function. This name will be used everywhere inside the chat.

ChatCamp.updateUserDisplayName(USER_NAME, new ChatCamp.UserUpdateListener() {
  @Override
  public void onUpdated(User user, ChatCampException e) {
    //Display name has been updated.
  }
});

6. Create an OpenChannel

Let's create an open channel which users will join and send messages.

OpenChannel.create(mChannelName.getText().toString(), new OpenChannel.CreateListener() {
  @Override
  public void onResult(OpenChannel openChannel) {
    //New open channel has been created.
  }
});

7. Join this newly created Open Channel

After creating Open Channel you would need to join it in order to be able to receive live messages and send new messages on behalf of your user.

OpenChannel.get(CHANNEL_ID, new OpenChannel.GetListener() {
  @Override
  public void onResult(OpenChannel openChannel) {

    //Open Channel details.

    openChannel.join(new OpenChannel.JoinListener() {
      @Override
      public void onResult() {
        //Open Channel joined.     

      }
    });
  }
});

8. Send a message

Now let's send a message to the channel.

openChannel.sendMessage(MESSAGE, new OpenChannel.SendMessageListener() {
  @Override
  public void onSent(Map data) {
    //Message has been delivered to the server.
  }
});