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:
1
public class MainApp extends Application {
2
​
3
@Override
4
public void onCreate() {
5
super.onCreate();
6
​
7
// Chat SDK intialization goes here
8
​
9
}
10
}
Copied!
Register this class in your AndroidManifest.xml:
1
<application android:name=".MainApp">
Copied!
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
1
ChatSDKFirebase.quickStart(...);
Copied!
FireStream
1
ChatSDKFireStream.quickStart(...);
Copied!
XMPP
1
ChatSDKXMPP.quickStart(...);
Copied!

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:
1
ChatSDKFirebase.quickStartWithEmail(...);
2
ChatSDKFirebase.quickStartWithGithubSponsors(...);
3
ChatSDKFirebase.quickStartWithPatreon(...);
Copied!

Builder

1
ChatSDK.builder() .... .build().activateWithPatreon(...)
2
ChatSDK.builder() .... .build().activateWithGithubSponsors(...)
3
ChatSDK.builder() .... .build().activateWithEmail(...)
Copied!

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.
1
try {
2
ChatSDK.builder()
3
.setGoogleMaps("Your Google Static Maps API key")
4
.setPublicChatRoomLifetimeMinutes(TimeUnit.HOURS.toMinutes(24))
5
.build()
6
​
7
// Add the Firebase network adapter module
8
.addModule(
9
FirebaseModule.builder()
10
.setFirebaseRootPath("pre_1")
11
.setDevelopmentModeEnabled(true)
12
.build()
13
)
14
​
15
// Add the UI module
16
.addModule(UIModule.builder()
17
.setPublicRoomCreationEnabled(true)
18
.setPublicRoomsEnabled(true)
19
.build()
20
)
21
​
22
// Add modules to handle file uploads, push notifications
23
.addModule(FirebaseUploadModule.shared())
24
.addModule(FirebasePushModule.shared())
25
​
26
// Enable Firebase UI with phone and email auth
27
.addModule(FirebaseUIModule.builder()
28
.setProviders(EmailAuthProvider.PROVIDER_ID, PhoneAuthProvider.PROVIDER_ID)
29
.build()
30
)
31
​
32
// Activate
33
.build()
34
.activate(this);
35
} catch (Exception e) {
36
e.printStackTrace();
37
}
Copied!
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.
Last modified 7mo ago