NowChatService クラス: Android
NowChatService クラスは、NowChat アクティビティを起動してエラー構成を設定できる関数を提供します。
NowChatService - launchIntent(context:Context, themeColors:NowChatTheme):インテント
NowChat アクティビティを開くために使用されるインテントを起動します。通常は [android.app.PendingIntent] の作成に使用されます。
| 名前 | タイプ | 説明 |
|---|---|---|
| context | コンテキスト | インテントをビルドするために使用されるコンテキスト。 |
| themeColor | NowChatテーマ | オプション。NowChat UI で使用するテーマの色。 デフォルト:デフォルトの色 |
| タイプ | 説明 |
|---|---|
| インテント | 関連する NowChat アクティビティを起動するために使用されるインテントとテーマの色。 |
この例では、 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(), chatConfiguration: NowChatConfiguration? = null)
指定された NowChat アクティビティを起動します。
| 名前 | タイプ | 説明 |
|---|---|---|
| アクティビティ | Activity (アクティビティ) | NowChat アクティビティを起動し、onActivityResult を介して NowChatExitCode を resultCode として受け取るために使用するアクティビティコンテキスト。 |
| themeColor | NowChatテーマ | オプション。NowChat UI で使用するテーマの色。 デフォルト:デフォルトの色 |
| コンテキストデータ | map<string、任意> | オプション。チャットセッションに渡す追加のチャットコンテキスト変数。 チャットコンテキスト変数の詳細については、「 Live agent chat context variables」を参照してください。 |
| チャット構成 | NowChatConfiguration | オプション。 NowChat を使用する際に適用する ChatConfiguration。 |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、この関数を呼び出す方法を示しています。
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")
//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)
未読チャットメッセージ数リスナーに登録します。
| 名前 | タイプ | 説明 |
|---|---|---|
| ポーリング間隔 | 長 | 未読チャットメッセージ数について Web サービスをポーリングする頻度。 単位:ミリ秒 |
| リスナー | NowChatUnreadMessagesCountListener | 未読チャットメッセージの数を取得するために実装するリスナー。また、 NowChatService - unsubscribeFromUnreadMessageCount(リスナー: NowChatUnreadMessagesCountListener) メソッドを使用して未読メッセージ数を取得する必要がなくなった場合にも、このリスナーを登録解除する必要があります。 |
| タイプ | 説明 |
|---|---|
| なし |
次の例は、チャット未読メッセージカウントリスナーに登録および登録解除する方法を示しています。
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)
未読メッセージ数の受信を登録解除します。
| 名前 | タイプ | 説明 |
|---|---|---|
| リスナー | NowChatUnreadMessagesCountListener | チャットの未読メッセージ数リスナーを登録解除するために実装するリスナー。 |
| タイプ | 説明 |
|---|---|
| なし |
次の例は、チャット未読メッセージカウントリスナーに登録および登録解除する方法を示しています。
private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
}
}
fun setup() {
nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}
fun teardown() {
nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}