---
sourceDocument: Referência de API do Brasil
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/api-reference

 Release :

    - brazil

ft:locale :

    - pt-BR

ft:publication_title :

    - Referência de API do Brasil

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Classe do Now ChatService - Android

# Classe do Now ChatService - Android {#ariaid-title1}

Versão de lançamento: Brazil  
Atualizado 10 de set. de 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 min. de leitura  
A classe NowChatService fornece funções que permitem iniciar a atividade do NowChat e definir configurações de erro.

## LaunchIntent(context:context, nowChatTheme:NowChatTheme):Intent {#ariaid-title2}

Inicia a intenção usada para abrir a atividade do NowChat. Normalmente usado para criar um `[android.app.PendingIntent]`.
{#NChatServA-launchIntent_O_O__table_yv2_43l_nrb__entry__3}{#NChatServA-launchIntent_O_O__Chat-themeColors-ph}

| Nome | Tipo | Descrição |
|-|-|-|
| contexto | Contexto | Contexto usado para criar a intenção. |
| Now ChatTheme | [NowChatTema](https://servicenow-prod.fluidtopics.net/6uBQJwpG2uRJeAeZwsapZw "A interface do NowChatTheme define cores padrão para os elementos na AtendenteVirtual Agent IU do bate-papo e.") | Opcional. Objeto de tema a ser usado na IU do NowChat. Padrão: Cores padrão |
[Tabela 1. Parâmetros]

{#NChatServA-launchIntent_O_O__table_yv2_43l_nrb} {#NChatServA-launchIntent_O_O__table_zv2_43l_nrb__entry__2}

| Tipo | Descrição |
|-|-|
| Intenção | Cores de intenção e tema usadas para iniciar a atividade do Now Chat associada. |
[Tabela 2. Retorna]

{#NChatServA-launchIntent_O_O__table_zv2_43l_nrb}  
Este exemplo mostra como chamar o método launchIntent() e processar a atividade de retorno.

    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: \<String, Any\>: MapOf(), chatConfiguration: NowChatConfiguration? nulo) {#ariaid-title3}

Inicia a atividade especificada do NowChat.
{#NChatServA-start_O_O__table_lbg_cyg_tpb__entry__3}{#NChatServA-start_O_O__Chat-themeColors-ph}

| Nome | Tipo | Descrição |
|-|-|-|
| atividade | [Atividade](https://developer.android.com/reference/kotlin/android/app/Activity.html) | Contexto de atividade a ser usado para iniciar a atividade do NowChat e receber o `NowChatExitCode` como um resultCode por meio do onActivityResult. |
| Now ChatTheme | [NowChatTema](https://servicenow-prod.fluidtopics.net/6uBQJwpG2uRJeAeZwsapZw "A interface do NowChatTheme define cores padrão para os elementos na AtendenteVirtual Agent IU do bate-papo e.") | Opcional. Objeto de tema a ser usado na IU do NowChat. Padrão: Cores padrão |
| ContextData | Map\<String, Any\> | Opcional. Variáveis de contexto de bate-papo adicionais para passar para a sessão de bate-papo. Para obter informações adicionais sobre variáveis de contexto de bate-papo, consulte [Live agent chat context variables](https://www.servicenow.com/docs/access?context=live-agent-chat-context-vars&version=brazil&pubname=brazil-conversational-interfaces&ft:locale=en-US). |
| Configuração do bate-papo | [NowChatConfiguration](https://servicenow-prod.fluidtopics.net/cI1hPWSVMhr_yGR373~tjw#NowChatOptionsAndroid "A classe NowChatConfiguration permite configurar opções em uma sessão de bate-papo, como mostrar um prompt antes de fechar uma janela de bate-papo, desabilitar recursos ao usar o bate-papo, aplicar diferentes opções de conversa ao usar o bate-papo e configurar componentes de IU no NowChat.") | Opcional. Configuração do Chata ser aplicada ao usar o NowChat. |
[Tabela 3. Parâmetros]

{#NChatServA-start_O_O__table_lbg_cyg_tpb} {#NChatServA-start_O_O__table_mbg_cyg_tpb__entry__2}

| Tipo | Descrição |
|-|-|
| Nenhum(a) |   |
[Tabela 4. Retorna]

{#NChatServA-start_O_O__table_mbg_cyg_tpb}  
O exemplo de código a seguir mostra como chamar esta função.

    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, ouvinte: NowChatUnreadMessagesCountListener) {#ariaid-title4}

Assina o ouvinte de contagem de mensagens de bate-papo não lidas.
{#NChatServA-subToUnreadMsgCnt_I_O__table_zrg_k1m_cqb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| PollingInterval | Longa | A frequência com que o serviço web deve ser pesquisado para a contagem de mensagens de bate-papo não lidas. Unidade: Milissegundos |
| listener | NowChatUnreadMessagesCountListener | Ouvinte que você implementa para obter o número de mensagens de bate-papo não lidas. Você também deve cancelar a assinatura deste ouvinte quando não quiser mais obter a contagem de mensagens não lidas usando o [NowChatService - unsubscribeFromUnreadMessageCount(ouvinte: NowChatUnreadMessagesCountListener)](https://servicenow-prod.fluidtopics.net/EZm1fErF2yhqKXdsvnjzZw#NChatServA-unsubFromUnreadMsgCnt_O "O recebimento da contagem de mensagens não lidas foi cancelado.") método. |
[Tabela 5. Parâmetros]

{#NChatServA-subToUnreadMsgCnt_I_O__table_zrg_k1m_cqb} {#NChatServA-subToUnreadMsgCnt_I_O__table_asg_k1m_cqb__entry__2}

| Tipo | Descrição |
|-|-|
| Nenhum(a) |   |
[Tabela 6. Retorna]

{#NChatServA-subToUnreadMsgCnt_I_O__table_asg_k1m_cqb}  
O exemplo a seguir mostra como assinar e cancelar a assinatura de um ouvinte de contagem de mensagens não lidas de bate-papo.

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

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

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

## NowChatService - unsubscribeFromUnreadMessageCount(ouvinte: NowChatUnreadMessagesCountListener) {#ariaid-title5}

O recebimento da contagem de mensagens não lidas foi cancelado.
{#NChatServA-unsubFromUnreadMsgCnt_O__table_inp_hbm_cqb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| listener | NowChatUnreadMessagesCountListener | Ouvinte que você implementa para cancelar a assinatura do ouvinte de contagem de mensagens não lidas do bate-papo. |
[Tabela 7. Parâmetros]

{#NChatServA-unsubFromUnreadMsgCnt_O__table_inp_hbm_cqb} {#NChatServA-unsubFromUnreadMsgCnt_O__table_jnp_hbm_cqb__entry__2}

| Tipo | Descrição |
|-|-|
| Nenhum(a) |   |
[Tabela 8. Retorna]

{#NChatServA-unsubFromUnreadMsgCnt_O__table_jnp_hbm_cqb}  
O exemplo a seguir mostra como assinar e cancelar a assinatura de um ouvinte de contagem de mensagens não lidas de bate-papo.

    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) {#ariaid-title6}

Atualiza o tema de IU do NowChat com o tema de IU especificado. Use esta função para atualizar o tema de IU de bate-papo depois que ele tiver sido definido inicialmente usando a função start(), como ao mudar o tema de claro para escuro.
{#NCharServA-updateTheme_O__table_yzy_5jv_x2c__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Now ChatTheme | [NowChatTema](https://servicenow-prod.fluidtopics.net/6uBQJwpG2uRJeAeZwsapZw "A interface do NowChatTheme define cores padrão para os elementos na AtendenteVirtual Agent IU do bate-papo e.") | Objeto de tema a ser usado na IU do NowChat. |
[Tabela 9. Parâmetros]

{#NCharServA-updateTheme_O__table_yzy_5jv_x2c} {#NCharServA-updateTheme_O__table_zzy_5jv_x2c__entry__2}

| Tipo | Descrição |
|-|-|
| Nenhum(a) |   |
[Tabela 10. Retorna]

{#NCharServA-updateTheme_O__table_zzy_5jv_x2c}  
O exemplo de código a seguir mostra como atualizar um tema de IU claro implementado usando a função start() para o tema de IU escuro usando a função updateTheme().

    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)


