🤖
Android
  • Chat SDK Android
  • Getting Started
    • Chat SDK Quickstart
    • Add the Chat SDK to a Firebase app
    • Add the Chat SDK to a non-Firebase app
  • Setup
    • Add Chat SDK to your project
    • Firebase Setup
    • Chat SDK Initialization
    • Set the Chat SDK Theme
    • Enable Location Messages
    • Authentication Screen
    • Add Additional Modules
    • Module Configuration
    • Proguard
  • API
    • Overriding Activities and Fragments
    • Events
    • Theming
    • Customizing the Icons
    • Tab Customization
    • Add a Chat Option
    • Message Customization
    • Integrating Chat SDK User profiles with your app
    • Overriding the Push Notification Handler
    • Handling Structured Meta Data
  • Chat SDK v4
    • Development Guide
    • Updating from v4 to v5
Powered by GitBook
On this page
  • Setup main application subclass
  • Configure Chat SDK
  • Pro Modules

Was this helpful?

  1. Setup

Chat SDK Initialization

Setup main application subclass

The best place to initialize the Chat SDK is in the onCreate method of your Application subclass.

If you don't already have this class, create it:

public class MainApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // Chat SDK intialization goes here

    }
}

Register this class in your AndroidManifest.xml:

<application android:name=".MainApp">

Note: Sometimes people confuse the onCreate method in the main activity with the onCreate method from the Activity class. Although in some cases it is possible to setup the Chat SDK from inside an activity, it is not recommended.

Configure Chat SDK

Chat SDK offers two ways to configure the library - quick config and advanced. Quick allows you get the project up and running with a standard configuration.

Quick Start

Firebase

ChatSDKFirebase.quickStart(...);

FireStream

ChatSDKFireStream.quickStart(...);

XMPP

ChatSDKXMPP.quickStart(...);

Pro Modules

If you want to use the licensed modules you will need to provide an identifier. That can be your Patreon ID, your Github Sponsors username, or the email address you used to buy the license at chatsdk.co.

Quick Start

You can use:

ChatSDKFirebase.quickStartWithEmail(...);
ChatSDKFirebase.quickStartWithGithubSponsors(...);
ChatSDKFirebase.quickStartWithPatreon(...);

Builder

ChatSDK.builder() .... .build().activateWithPatreon(...)
ChatSDK.builder() .... .build().activateWithGithubSponsors(...)
ChatSDK.builder() .... .build().activateWithEmail(...)

Advanced Configuration

Builder pattern

The Chat SDK and its modules use the builder pattern for configuration. You will always call builder() then set your configuration then call build() to finish.

Modules

The Chat SDK contains a number of optional modules. These can be added with the addModule method. At the very minimum, you should activate the UIModule and one of FirebaseModule, XMPPModule or FireStreamModule.

Full example

Here is a default configuration.

try {
    ChatSDK.builder()
            .setGoogleMaps("Your Google Static Maps API key")
            .setPublicChatRoomLifetimeMinutes(TimeUnit.HOURS.toMinutes(24))
            .build()

            // Add the Firebase network adapter module
            .addModule(
                    FirebaseModule.builder()
                            .setFirebaseRootPath("pre_1")
                            .setDevelopmentModeEnabled(true)
                            .build()
            )

            // Add the UI module
            .addModule(UIModule.builder()
                    .setPublicRoomCreationEnabled(true)
                    .setPublicRoomsEnabled(true)
                    .build()
            )

            // Add modules to handle file uploads, push notifications
            .addModule(FirebaseUploadModule.shared())
            .addModule(FirebasePushModule.shared())

            // Enable Firebase UI with phone and email auth
            .addModule(FirebaseUIModule.builder()
                    .setProviders(EmailAuthProvider.PROVIDER_ID, PhoneAuthProvider.PROVIDER_ID)
                    .build()
            )

            // Activate
            .build()
            .activate(this);
} catch (Exception e) {
    e.printStackTrace();
}

Configuration options

The Chat SDK has many configuration options. Too many to list here. The best way to see what's available is by using auto-complete in Android Studio. After module.build(). press (control + enter) and the list of available options will appear. You can also (cmd + click) to inspect the Config class and see a full list of the available options.

PreviousFirebase SetupNextSet the Chat SDK Theme

Last updated 4 years ago

Was this helpful?