In this series of tutorials we are going to see how to develop a basic Android Chat Application with GCM (Google Cloud Messaging) , Node.js server and MongoDB database.
What we will do ?
-> Login User and store data temporarily in MongoDB database.
-> Upstream Messaging through Node.js server.
-> Downstream Messaging using GCM.
-> Shows user who are logged in.
-> Notification displayed when new message arrived.
-> Remove data from database when user logged out.
-> Persistance with Shared Preferences.
Our tutorial has two major parts
1. Setting up server with Node.js, MongoDB, GCM.
2. Develop client side Android Application for chatting.
Setting up Server Side
Registering you Application with GCM (Google Cloud Messaging)
1. Open Google Developer Console .
2. Create a new Project.
3. Select Overview and note down the Project number.
4. In the left pane under APIs & auth select APIs and enable Google Cloud Messaging for Android.
5. Then select Credentials section.
6. Create a new Key select type as Server key. Enter the IP of your server. If you are testing in localhost enter the IP as 0.0.0.0/0.
See the following tutorial to setup Node.js and MongoDB in your Linux or Windows machines.
Use the GUI client Robomongo to access MongoDB. It is available for all the platforms.
Download Complete Project
Creating the project
-> Create a MongoDB database named node-android-chat using Robomongo.
-> Now enter npm install in Linux terminal or windows command prompt.
-> Now all the packages begins downloading and it is available in the directory node_modules.
Lets see why we use these packages.
express is a Node.js framework. It is used to simplify some of the basic tasks.
mongoose is a Node.js module which is used to interact easily with MongoDB databases.
Connect is a express middleware which is used to parse form data, and to use logger which prints the request in the terminal.
Request is used to sent Requests such as POST from our Node.js server to GCM server.
Create a file named app.js in the root of the node-android folder. It is the main file which makes our server up and run. Here our application runs on the port 8080 in localhost.
If you wish to receive new articles related to Android Chat Application using GCM (Google Cloud Messaging) – Server #1 enter your email address in the field below and subscribe: