We chat application for Android
In this blog post, we’ll walk you through how to build an Android group chat application with a number of different core chat features. We’ll cover how to build:
- Basic messaging for multi-user group chat
- Presence: ie. the ‘buddy list’ (live online/offline status of connected users)
- History: stores and retrieves messages
- Push notifications
In the end, you’ll have something that looks like the sample image below. Check out the .
Project Details
Our Android group chat app allows a user to create a login identity that is then stored inSharedPreferences until logout. The initial chat room is titled MainChat, but a user can change chat rooms at any time.
An integer in the menu bar indicates how many users are in the current chat room. If you click that here now number, a modal with all users in the room is displayed. Clicking on a user in the herenow modal will display the login time of the corresponding user.
Clicking on a message in the chat room will send a poke to that user, notifying them that you are in the chat room.
Core Chat Messaging
When a user sends a message, the code creates a ChatMessage object that holds the username, message text, and timestamp for the given message. ChatMessages are then serialized into a JSONObject and published to all users on the current channel via PubNub.
Next, a message is received using PubNub’s subscribe method. The JSONObject is deserialized back into a ChatMessage and added to a list of messages from the current chat room.
Realtime User Online/Offline List
If a user is online, a green dot is displayed next to their name. Join and Leave events are updated in realtime as well, so when a user logs off, you are notified immediately.
Presence updates the number of users currently in a room, but when you want to see the users currently in the chat, hereNow is used. A modal opens and is populated with the users currently subscribed to the chat room. Clicking on a user will tell you their login time, and the modal can be dismissed by clicking done.
Historic Messages
To store and retrieve historic chat messages, Storage & Playback is used. When a user opens the Android group chat app and is sent to MainChat, or when a user changes rooms, a call to PubNub’s history function loads the last 100 messages from the current channel so you know what other users have been talking about when you join.
Last Login
The PubNub State API allows you to define state data on the current channel. You can attach an object to your UUID that is accessible to anyone on the channel. This chat app uses the state API to attach login time to all online users’ UUIDs. When a user in the here now modal is clicked, their login time is read from the state of the channel and displayed in a Toast message.
Push Notifications
Enable push notifications on a channel and attach your GCM device ID to that channel and you are all set to receive pushes. When you tap a user’s message in a chat room, a PubNub push notification is sent through GCM protocols to notify the user that you are waiting for them.
Source: www.pubnub.com
![]() |
We Chat (Parenting) Mobile Application (The Idea Monk)
|
You might also like:



![]() |
MKS Staff Mobile Application (Gonext Info Solutions)
|



![]() |
SecureO Mobile Application (SecureO)
|
![]() |
Funny Whats App Stickers Mobile Application (chattingstickers)
|
![]() |
WhatsApp Mobile Application (WhatsApp, Inc.)
|