MyS3Chat — Complete Open Source Real-Time Android Chat Application using Firebase

Mudasir Younas
The Startup
Published in
4 min readJul 24, 2019
MyS3Chat — Complete Open Source Real Time Android Chat Application using Firebase

In this tutorial we will be developing real-time chat application using firebase, At the end of this tutorial, you will have a complete working android application ready to be published on playstore, excited? Let’s get started.

Download code from Github.

Install from Playstore.

This tutorial assumes that you have basic knowledge of Java and Android SDK, you have built through small android applications and you are ready to apply your learning on some real projects.

Prerequisites:

· Android studio is installed and Android SDK is configured

· Android Physical or virtual device is ready for testing our application

· An account of firebase real-time database

What is firebase real-time database?

The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data between your users in realtime. We will be using this database to sync data between users and show notification whenever a new message arrives.

What is Retrofit:

Retrofit is an HTTP client for android, we will be using this library to parse firebase responses.

What is SQLite:

SQLite is a local database which we will use to store data already fetched from the server to avoid sending request each time a user opens a chat activity.

Alright, so I will not be going to each code and explain what the code is doing rather explain some important classes and leave the rest for you play with.

ActivityMain.java

This will be our main activity where the user first lands, In this activity we will be first checking if a user is logged in and redirecting him to ActivityLogin if not logged in. After successfully logging in, the first thing we will be showing on our application’s main activity is chat history (if there is any), that’s what any user will be looking for.

At the very first login, we fetch data from firebase and store in local DB using SQLite, and at the later we do fetch chat history from the end user’s local storage.

To avoid main thread freezing, each request to the network is made in a new task.

ActivityChat.java

After successfully showing chat history user can click on any friends chat and we will send him to chat activity. If the user does not have any contacts he can goto search option, where he can search by name, email, and send a connection request.

AppService.java
This class is responsible for listening to firebase and Show users a notification whenever there is any new activity, new message, new connection request, etc.

DataContext.java
This is the class where we handle all local data storage for getting chat history, getting contact lists, deleting contacts, saving the new message to local storage, etc.

IFireBaseAPI.java
In this class, I have implemented retrofit API to get a response from the firebase as a JSON string.

That’s it, clone the project from GitHub, build on your android studio and there you have complete working android application, as I promised.

This project is not very complex, but it’s also not very easy to understand if you have just landed your feet on the android World.

Please feel free to contact me for any problem or if you don’t understand any part or if you just want to say hello.

Screenshots of running application.

Important Note:

The firebase account currently used in this application is public, which means anything you enter while testing the application is publicly available, you may keep using this account for testing purpose but please make sure you change the firebase account after testing.

Official References:

Android Studio: https://developer.android.com/studio

Firebase: https://firebase.google.com/docs/database

Firebase Android Setup: https://firebase.google.com/docs/database/android/start

Retrofit2: https://square.github.io/retrofit/

Thank you for reading my article, if you have any problem or questions, please reach me out on Twitter or LinkedIn.

--

--