banner 728x90

How to Add Messaging to your Android App

In Mobile Web Development 72 views
banner 728x90

1x1.trans - How to Add Messaging to your Android AppThe BBM Enterprise SDK makes it easy to integrate a messaging experience into your application. Messaging within the BBM Enterprise SDK allows users to share text, files, pictures, or custom data defined by you. Let’s take a look at how the SimpleChat sample displays a conversation style message list.

The BBM Enterprise SDK comes with a collection of utility classes (provided as source code for your convenience) that help you accelerate your development.

The ChatMessageList is one of these utilities. It provides an indexed list of chat messages that are lazily loaded, so that you don’t have to worry about your message history’s performance as the chat grows with thousands of messages.

Using the ChatMessageList coupled with Android’s RecyclerView framework to display the messages within a chat, you can achieve smooth and fluid scrolling in your message list, with older messages lazily loading as you scroll back to view them.

To start, instantiate a ChatMessageList with the id of the chat whose messages you want to display, and an IncrementalListObserver to notify your RecyclerView.Adapter whenever a message is added, removed, or changed.

 

mChatMessageList = new ChatMessageList(mChatId);

mChatMessageList.addIncrementalListObserver(mMessageListObserver);

The IncrementalListObserver is added to your ChatMessageList as an observer.

private IncrementalListObserver mMessageListObserver = new IncrementalListObserver() ;

Call start() and stop() on the ChatMessageList to start/stop listening to changes on your messages. This will cause your adapter to only update when the chat is displayed to the user.

@Override

protected void onPause()

@Override

protected void onResume()

Creating Chat Message Views

In this example, we display simple text messages, but the BBM Enterprise SDK also supports files, pictures, contacts, calendar, location, voice notes, or any custom data types you define.

Your RecyclerView.Adapter will create and update the views for the chat messages. Simply update your message view’s text field with the ChatMessage.content. You can also left or right align your outgoing and incoming messages by creating different view types based on the Incoming flag on the ChatMessage object.

private class MessageViewHolder extends RecyclerView.ViewHolder

 

private RecyclerView.Adapter mAdapter = new RecyclerView.Adapter<MessageViewHolder>() ;

Next Steps

Adding a messaging experience to your application is made simple with the BBM Enterprise SDK. You can download this example and follow a step by step walkthrough by visiting the BBM Enterprise SDK developer portal and downloading the BBM Enterprise SDK today.

banner 728x90
author
Author: 
    Build a user settings store with AWS AppSync
    Build a user settings store with AWS AppSync
    Amazon Cognito Sync is a service that
    Synchronize user settings for Android with AWS AppSync
    Synchronize user settings for Android with AWS AppSync
    Amazon Cognito Sync is a service that
    Script & Style Show: Episode 10: Dojo
    Script & Style Show: Episode 10: Dojo
    In this episode welcome David and Todd

    Leave a reply "How to Add Messaging to your Android App"

    Must read×

    Top