Java
Receive new messages
You can display incoming messages by implementing the conversation listener.
Now, locate the getConversation method and add addMessageEventListener call:
private void getConversation() {
client.getConversation(CONVERSATION_ID, new NexmoRequestListener<NexmoConversation>() {
@Override
public void onSuccess(@Nullable NexmoConversation conversation) {
MainActivity.this.conversation = conversation;
getConversationEvents(conversation);
conversation.addMessageEventListener(new NexmoMessageEventListener() {
@Override
public void onMessageEvent(@NonNull NexmoMessageEvent messageEvent) {
conversationEvents.add(messageEvent);
updateConversationView();
}
@Override
public void onTextEvent(@NonNull NexmoTextEvent textEvent) {}
@Override
public void onAttachmentEvent(@NonNull NexmoAttachmentEvent attachmentEvent) {}
@Override
public void onEventDeleted(@NonNull NexmoDeletedEvent deletedEvent) {}
@Override
public void onSeenReceipt(@NonNull NexmoSeenEvent seenEvent) {}
@Override
public void onDeliveredReceipt(@NonNull NexmoDeliveredEvent deliveredEvent) {}
@Override
public void onTypingEvent(@NonNull NexmoTypingEvent typingEvent) {}
});
}
@Override
public void onError(@NonNull NexmoApiError apiError) {
MainActivity.this.conversation = null;
Toast.makeText(MainActivity.this, "Error: Unable to load conversation", Toast.LENGTH_SHORT);
}
});
}
Each time a new message is received public void onMessageEvent(@NonNull NexmoMessageEvent messageEvent) listener is called, the new message will be added to the conversationEvents collection and updateConversationView method will be called to reflect the changes.
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 Java.
Steps
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?