Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

NowChatService class- Android

The NowChatService class provides functions that enable you to launch the NowChat activity and set error configurations.

Parent Topic:Mobile SDK - Android

NowChatService - launchIntent(context:Context, nowChatTheme:NowChatTheme):Intent

Launches the intent used to open the NowChat activity. Typically used for creating a [android.app.PendingIntent].

NameTypeDescription
contextContextContext used to build the intent.
nowChatThemeNowChatThemeOptional. Theme object to use in the NowChat UI.Default: Default colors
TypeDescription
IntentIntent and theme colors used to launch the associated NowChat activity.

This example shows how to call the launchIntent() method and process the return activity.

val intent = nowChatService.launchIntent(this) 
val pendingIntent = PendingIntent.getActivity( 
    this, 
    REQUEST_CODE,
    intent,
    PendingIntent.FLAG_IMMUTABLE 
) 

val notification = createNotification(title, message, pendingIntent)
notificationManager.notify(push.notificationId, notification) 

NowChatService - start(activity: Activity, themeColors: NowChatTheme = object: NowChatTheme{}, contextData: Map<String, Any> = mapOf(), chatConfiguration: NowChatConfiguration? = null)

Launches the specified NowChat activity.

NameTypeDescription
activityActivityActivity context to use to launch the NowChat activity and to receive the `NowChatExitCode` as a resultCode through the onActivityResult.
nowChatThemeNowChatThemeOptional. Theme object to use in the NowChat UI.Default: Default colors
contextDataMap<String, Any>Optional. Additional chat context variables to pass into the chat session.For additional information on chat context variables, see Live agent chat context variables.
chatConfigurationNowChatConfigurationOptional. ChatConfiguration to apply while using NowChat.
TypeDescription
None 

The following code example shows how to call this function.

suspend fun launchChat() {
    val chatService = getNowChatService()

    val chatTheme = object : NowChatTheme {
        override val brand: Int
            get() = Color.BLUE

        override val textPrimary: Int
            get() = Color.BLACK

        // Override remaining theme colors

    }
    val contextData = mapOf("sys_id" to "123456789", "table" to "wm_task")

    //drawable to be used instead of the default NowChat back button.
    val myDrawable = ContextCompat.getDrawable(activity, R.drawable.my_drawable)

    val chatConfiguration = NowChatConfiguration(
        closePrompt = NowChatConfiguration.ClosePrompt(
            header = null,
            message = "Are you sure you want to leave?",
            acceptButtonTitle = "Yes",
            declineButtonTitle = "No"
        ),
        disabledFeatures = listOf(NowChatConfiguration.Feature.START_NEW_CONVERSATION),
        conversationOptions = listOf(NowChatConfiguration.ConversationOption.FORCE_NEW_CONVERSATION),
        uiConfiguration = NowChatConfiguration.UIConfiguration(
            closeButton = NowChatConfiguration.CloseButton(
                icon = myDrawable
            ),
            attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
        )
    )

    chatService?.start(activity, chatTheme, contextData, chatConfiguration)
}

NowChatService - subscribeToUnreadMessageCount(pollingInterval: Long, listener: NowChatUnreadMessagesCountListener)

Subscribes to the unread chat message count listener.

NameTypeDescription
pollingIntervalLongFrequency at which to poll the web service for the unread chat message count.Unit: Milliseconds
listenerNowChatUnreadMessagesCountListenerListener that you implement to obtain the number of unread chat messages. You must also unsubscribe to this listener when you no longer want to obtain the unread message count using the NowChatService - unsubscribeFromUnreadMessageCount(listener: NowChatUnreadMessagesCountListener) method.
TypeDescription
None 

The following example shows how to subscribe to and unsubscribe from a chat unread message count listener.

private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
  override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
  }
}

fun setup() {
  nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}

fun teardown() {
  nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}

NowChatService - unsubscribeFromUnreadMessageCount(listener: NowChatUnreadMessagesCountListener)

Unsubscribes from receiving the unread message count.

NameTypeDescription
listenerNowChatUnreadMessagesCountListenerListener that you implement to unsubscribe from the chat unread message count listener.
TypeDescription
None 

The following example shows how to subscribe to and unsubscribe from a chat unread message count listener.

private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
  override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
  }
}

fun setup() {
  nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}

fun teardown() {
  nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}

NowChatService – updateTheme(nowChatTheme: NowChatTheme)

Updates the NowChat UI theme with the specified UI theme. Use this function to update the chat UI theme after it has been initially set using the start() function, such as when changing the theme from light to dark.

NameTypeDescription
nowChatThemeNowChatThemeTheme object to use in the NowChat UI.
TypeDescription
None 

The following code example shows how to update a light UI theme implemented using the start() function to the dark UI theme using the updateTheme() function.

val chatService = serviceManager.getNowChatService()

val chatThemeLight = object : NowChatTheme {
    override val backgroundPrimary: Int
        get() = Color.WHITE

    override val textPrimary: Int
        get() = Color.BLACK

    // Override remaining theme colors
}

val chatThemeDark = object : NowChatTheme {
    override val backgroundPrimary: Int
        get() = Color.BLACK

    override val textPrimary: Int
        get() = Color.WHITE

    // Override remaining theme colors
}

//start NowChat with light theme
chatService?.start(activity, chatThemeLight)


//update NowChat theme to dark theme
chatService?.updateTheme(chatThemeDark)