Skip to main content

Initialization

You must initialize the Chat UI SDK before using any Chat UI screens.

When to initialize

Call the initialization method in Application#onCreate():

kotlin
import ai.nexconn.chat.params.InitParams
import ai.nexconn.chatui.NCChatUI

override fun onCreate() {
super.onCreate()
val appKey = "Your_AppKey"
NCChatUI.initialize(InitParams(applicationContext, appKey))
}

Connect

After initialization, call the connect method when your business login succeeds:

kotlin
import ai.nexconn.chat.params.ConnectParams

val token = "Your_Token"
NCChatUI.connect(ConnectParams(token)) { userId, error ->
if (error == null) {
// Connection succeeded
} else {
// Connection failed
}
}

Disconnect and logout

kotlin
// Disconnect but keep push notifications enabled
NCChatUI.disconnect()

// Disconnect and disable push notifications
NCChatUI.logout()

Check initialization status

kotlin
if (NCChatUI.isInitialized()) {
// safe to use ChatUI APIs
}

Notes

  • Initialize only once per application lifecycle.
  • Initialize before connecting.
  • Manage connection listeners at the UI layer and handle errors appropriately.