---
sourceDocument: Xanadu API 참조
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ko-KR

ft:publication_title :

    - Xanadu API 참조

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowChatService 클래스 - Android

# NowChatService 클래스 - Android {#ariaid-title1}

* 릴리스 버전: Xanadu
* 
* 업데이트 날짜 2024년 08월 01일
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 소요 시간: 6분

NowChatService 클래스는 NowChat 활동을 시작하고 오류 구성을 설정할 수 있는 기능을 제공합니다.

## NowChatService - launchIntent(context:Context, themeColors:NowChatTheme):Intent {#ariaid-title2}

NowChat 활동을 여는 데 사용되는 의도를 시작합니다. 일반적으로 `[android.app.PendingIntent]`를 만드는 데 사용됩니다.
{#NChatServA-launchIntent_O_O__table_yv2_43l_nrb__entry__3}

| 이름 | 유형 | 설명 |
|-|-|-|
| 컨텍스트 | 컨텍스트 | 의도를 빌드하는 데 사용되는 컨텍스트입니다. |
| themeColors (테마 색상) | [NowChat테마](https://servicenow-prod.fluidtopics.net/8ps5E47Zf8Y3nzbMXolkAQ "NowChatTheme 인터페이스는 라이브 에이전트 및 가상 에이전트 채팅 UI의 요소에 대한 기본 색상을 정의합니다.") | 옵션입니다. NowChat UI에서 사용할 테마 색상입니다. 기본값: 기본 색상 |
[표 1. 매개변수]

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

| 유형 | 설명 |
|-|-|
| 의도 | 연결된 NowChat 활동을 시작하는 데 사용되는 의도 및 테마 색상입니다. |
[표 2. 반환]

{#NChatServA-launchIntent_O_O__table_zv2_43l_nrb}  
이 예제에서는 launchIntent() 메서드를 호출하고 반환 활동을 처리하는 방법을 보여 줍니다.

    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(), chatOptions: NowChatOptions? = null) {#ariaid-title3}

지정된 NowChat 활동을 시작합니다.
{#NChatServA-start_O_O__table_lbg_cyg_tpb__entry__3}

| 이름 | 유형 | 설명 |
|-|-|-|
| 활동 | [활동](https://developer.android.com/reference/kotlin/android/app/Activity.html) | NowChat 활동을 시작하고 onActivityResult를 통해 `NowChatExitCode`를 resultCode로 수신하는 데 사용할 활동 컨텍스트입니다. |
| themeColors (테마 색상) | [NowChat테마](https://servicenow-prod.fluidtopics.net/8ps5E47Zf8Y3nzbMXolkAQ "NowChatTheme 인터페이스는 라이브 에이전트 및 가상 에이전트 채팅 UI의 요소에 대한 기본 색상을 정의합니다.") | 옵션입니다. NowChat UI에서 사용할 테마 색상입니다. 기본값: 기본 색상 |
| 컨텍스트 데이터 | Map\<String, Any\> | 옵션입니다. 채팅 세션에 전달되는 추가 채팅 컨텍스트 변수입니다. 채팅 컨텍스트 변수에 대한 자세한 내용은 을 참조하십시오 [Live agent chat context variables](https://www.servicenow.com/docs/access?context=live-agent-chat-context-vars&version=xanadu&pubname=xanadu-conversational-interfaces&ft:locale=en-US). |
| chatOptions | [NowChatOptions](https://servicenow-prod.fluidtopics.net/3zmn6Uf7hW7ZXruX1Z2NZA#NowChatOptionsAndroid "NowChatOptions 클래스를 사용하면 채팅 창을 닫기 전에 프롬프트를 표시하고, 채팅을 사용하는 동안 기능을 사용하지 않도록 설정하고, 채팅 서비스가 시작될 때 새 채팅 대화를 강제 실행하는 등의 채팅 세션에 대한 옵션을 구성할 수 있습니다.") | 옵션입니다. 채팅 세션에 적용할 옵션입니다. |
[표 3. 매개변수]

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

| 유형 | 설명 |
|-|-|
| 없음 |   |
[표 4. 반환]

{#NChatServA-start_O_O__table_mbg_cyg_tpb}  
다음 코드 예제에서는 이 함수를 호출하는 방법을 보여 줍니다.

    suspend fun launchChat() { 
      val chatService = getNowChatService() 
      val chatTheme = object : NowChatTheme { 
        override val brand: NowUIAdaptiveColor 
        get() = NowUIAdaptiveColor(Color.BLUE) 
     
        override val textPrimary: NowUIAdaptiveColor 
        get() = NowUIAdaptiveColor(Color.BLACK) 
     
        // Override remaining theme colors 
     
      } 
      val contextData = mapOf("sys_id" to "123456789", "table" to "wm_task") 
     
      val chatOptions = NowChatOptions( 
        NowChatOptions.ClosePrompt( 
          header = null, 
          message = "Are you sure you want to leave?", 
          acceptButtonTitle = "Yes", 
          declineButtonTitle = "No" 
        ), 
        disabledFeatures = listOf(NowChatOptions.Feature.START_NEW_CONVERSATION), 
        forceNewConversation= true 
      )
     
       chatService?.start(activity, chatTheme, contextData, chatOptions) 
    } 

## NowChatService - subscribeToUnreadMessageCount(pollingInterval: Long, 수신기: NowChatUnreadMessagesCountListener) {#ariaid-title4}

읽지 않은 채팅 메시지 수 수신기를 구독합니다.
{#NChatServA-subToUnreadMsgCnt_I_O__table_zrg_k1m_cqb__entry__3}

| 이름 | 유형 | 설명 |
|-|-|-|
| pollingInterval (폴링인터벌) | 길게 | 읽지 않은 채팅 메시지 수에 대해 웹 서비스를 폴링하는 빈도입니다. 단위: 밀리초 |
| 경청자 | NowChatUnreadMessagesCountListener | 읽지 않은 채팅 메시지 수를 가져오기 위해 구현하는 수신기입니다. 또한 메서드를 사용하여 읽지 않은 메시지 수를 더 이상 가져오지 않으려는 경우 이 수신기의 구독을 [NowChatService - unsubscribeFromUnreadMessageCount(수신기: NowChatUnreadMessagesCountListener)](https://servicenow-prod.fluidtopics.net/rVb6nxXg9Q9KYQB3rfJEkA#NChatServA-unsubFromUnreadMsgCnt_O "읽지 않은 메시지 수 수신 구독을 취소합니다.") 취소해야 합니다. |
[표 5. 매개변수]

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

| 유형 | 설명 |
|-|-|
| 없음 |   |
[표 6. 반환]

{#NChatServA-subToUnreadMsgCnt_I_O__table_asg_k1m_cqb}  
다음 예제에서는 채팅 읽지 않은 메시지 수 수신기를 구독 및 구독 취소하는 방법을 보여 줍니다.

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

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

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

## NowChatService - unsubscribeFromUnreadMessageCount(수신기: NowChatUnreadMessagesCountListener) {#ariaid-title5}

읽지 않은 메시지 수 수신 구독을 취소합니다.
{#NChatServA-unsubFromUnreadMsgCnt_O__table_inp_hbm_cqb__entry__3}

| 이름 | 유형 | 설명 |
|-|-|-|
| 경청자 | NowChatUnreadMessagesCountListener | 채팅 읽지 않은 메시지 수 수신기에서 구독을 취소하기 위해 구현하는 수신기입니다. |
[표 7. 매개변수]

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

| 유형 | 설명 |
|-|-|
| 없음 |   |
[표 8. 반환]

{#NChatServA-unsubFromUnreadMsgCnt_O__table_jnp_hbm_cqb}  
다음 예제에서는 채팅 읽지 않은 메시지 수 수신기를 구독 및 구독 취소하는 방법을 보여 줍니다.

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

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

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


