Kotlin
Receive new messages
You can display incoming messages by implementing the conversation listener.
Now, locate the getConversation method and add addMessageEventListener call:
private fun getConversation() {
client.getConversation(CONVERSATION_ID, object : NexmoRequestListener<NexmoConversation?> {
override fun onSuccess(conversation: NexmoConversation?) {
this@MainActivity.conversation = conversation
conversation?.let {
getConversationEvents(it)
it.addMessageEventListener(object : NexmoMessageEventListener {
override fun onMessageEvent(messageEvent: NexmoMessageEvent) {
conversationEvents.add(messageEvent)
updateConversationView()
}
override fun onTextEvent(textEvent: NexmoTextEvent) {}
override fun onAttachmentEvent(attachmentEvent: NexmoAttachmentEvent) {}
override fun onEventDeleted(deletedEvent: NexmoDeletedEvent) {}
override fun onSeenReceipt(seenEvent: NexmoSeenEvent) {}
override fun onDeliveredReceipt(deliveredEvent: NexmoDeliveredEvent) {}
override fun onTypingEvent(typingEvent: NexmoTypingEvent) {}
})
}
}
override fun onError(apiError: NexmoApiError) {
conversation = null
Toast.makeText(this@MainActivity, "Error: Unable to load conversation", Toast.LENGTH_SHORT)
}
})
}
Now each time a new message is received onMessageEvent(messageEvent: NexmoMessageEvent) listener is called, the new message will be passed to updateConversation method and dispatched to the view via conversationEvents LiveData (same LiveData used to dispatch all the messages after loading conversation events).
Run the app
You can either launch the app on the physical phone (with USB Debugging enabled) or create a new Android Virtual Device. When device is present press Run button:

Creating an Android chat app
Create a Android application that enables users to message each other using the Android Client SDK and Kotlin.
手順
1
Introduction to this task2
Prerequisites3
Create a Vonage Application4
Create a conversation5
Create the users6
Add users to the conversation7
Generate JWTs8
Create an Android project9
Add permissions10
Build main screen11
Initialize the client12
Fetch the conversation13
Fetch conversation events14
Send a message15
Receive new messages16
What's next?