---
sourceDocument: オーストラリア API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/api-reference

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリア API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowChatService クラス : Android

# NowChatService クラス : Android {#ariaid-title1}

* リリースバージョン: Australia
* 
* 更新日 2026年03月12日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：9分

NowChatService クラスは、NowChat アクティビティを起動してエラー構成を設定できるようにする関数を提供します。

## NowChatService - launchIntent(context:Context, nowChatTheme:NowChatTheme):インテント {#ariaid-title2}

NowChat アクティビティを開くために使用されるインテントを起動します。通常、\[ `android.app.PendingIntent]` の作成に使用されます。
{#NChatServA-launchIntent_O_O__table_yv2_43l_nrb__entry__3}{#NChatServA-launchIntent_O_O__Chat-themeColors-ph}

| 名前 | タイプ | 説明 |
|-|-|-|
| コンテキスト | コンテキスト | インテントのビルドに使用されるコンテキスト。 |
| Now チャットテーマ | [NowChatテーマ](https://servicenow-prod.fluidtopics.net/qWozzfe4qumWrHePKTCgag "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() メソッドを呼び出して return アクティビティを処理する方法を示します。

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

指定された NowChat アクティビティを起動します。
{#NChatServA-start_O_O__table_lbg_cyg_tpb__entry__3}{#NChatServA-start_O_O__Chat-themeColors-ph}

| 名前 | タイプ | 説明 |
|-|-|-|
| アクティビティ | [アクティビティ](https://developer.android.com/reference/kotlin/android/app/Activity.html) | NowChat アクティビティを起動し、onActivityResult を介して `resultCode として NowChatExitCode` を受け取るために使用するアクティビティコンテキスト。 |
| Now チャットテーマ | [NowChatテーマ](https://servicenow-prod.fluidtopics.net/qWozzfe4qumWrHePKTCgag "NowChatTheme インターフェイスは、ライブエージェントおよび仮想エージェントチャット UI の要素のデフォルトの色を定義します。") | オプション。NowChat UI で使用するテーマオブジェクト。 デフォルト:デフォルトの色 |
| コンテキストデータ | マップ\<文字列、任意\> | オプション。チャットセッションに渡す追加のチャットコンテキスト変数。 チャットコンテキスト変数の詳細については、「 [Live agent chat context variables](https://www.servicenow.com/docs/access?context=live-agent-chat-context-vars&version=australia&pubname=australia-conversational-interfaces&ft:locale=en-US)」を参照してください。 |
| チャット構成 | [NowChat 構成](https://servicenow-prod.fluidtopics.net/ouaZkaMgNIq3RszsgcQDMQ#NowChatOptionsAndroid "NowChatConfiguration クラスを使用すると、チャットウィンドウを閉じる前のプロンプトの表示、チャットの使用中の機能の無効化、チャットの使用中のさまざまな会話オプションの適用、NowChat での UI コンポーネントの構成など、チャットセッションのオプションを構成できます。") | オプション。 NowChat の使用中に適用する ChatConfiguration。 |
[表 : 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: 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, リスナー: NowChatUnreadMessagesCountListener) {#ariaid-title4}

未読チャットメッセージカウントリスナーに登録します。
{#NChatServA-subToUnreadMsgCnt_I_O__table_zrg_k1m_cqb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| ポーリング間隔 | 長 | Web サービスをポーリングして未読チャットメッセージ数をポーリングする頻度。 単位：ミリ秒 |
| リスナー | NowChatUnreadMessagesCountListener | 未読チャットメッセージの数を取得するために実装するリスナー。また、 [NowChatService - unsubscribeFromUnreadMessageCount(リスナー:NowChatUnreadMessagesCountListener)](https://servicenow-prod.fluidtopics.net/Ti1IcD7_tIXEjZaCiUmEqw#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)
    }

## NowChatService -- updateTheme(nowChatTheme:NowChatTheme) {#ariaid-title6}

NowChat UI テーマを指定された UI テーマで更新します。テーマを明から暗に変更する場合など、 start() 関数で最初に設定したチャット UI テーマを更新するには、この関数を使用します。
{#NCharServA-updateTheme_O__table_yzy_5jv_x2c__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| Now チャットテーマ | [NowChatテーマ](https://servicenow-prod.fluidtopics.net/qWozzfe4qumWrHePKTCgag "NowChatTheme インターフェイスは、ライブエージェントおよび仮想エージェントチャット UI の要素のデフォルトの色を定義します。") | NowChat UI で使用するテーマオブジェクト。 |
[表 : 9. パラメーター]

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

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 10. 戻り値]

{#NCharServA-updateTheme_O__table_zzy_5jv_x2c}  
次のコード例は、updateTheme() 関数を使用して、start() 関数を使用して実装された明るい UI テーマを暗い UI テーマに更新する方法を示しています。

    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)


