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 theonCreate
method from theActivity
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.
Last updated
Was this helpful?