Loading...

Android Push Notification Tutorial Using Firebase

Firebase is a powerful platform for building Android, IOS and web based applications. Firebase offers real time data storage and synchronization, user authentication, analytics, hosting, database, remote configuration, notification, cloud messaging and lots more. Before the Google I/O 2016, we used Google Cloud Messaging service (GCM) to send data: notification, messages from the server to the clients or android app users. Google introduced the firebase cloud messaging in Google I/O 2016 and it makes developers very easy and fast to implement in their applications or games.

In this tutorial, you will learn to connect your android app to firebase to store data and push/send notification to the android app/game users using Google Firebase. Firebase is totally new and not the part of Google Cloud Platform.

Firebase offers both free plan and paid/pro plan. You can use analytic, app indexing, dynamic links, invites, authentication, notification, remote configuration, crash reporting, real-time database: 100 simultaneous connections, 1GB stored, 10 GB transferred and file storage: 5 GB storage, 30 GB transferred, 50,000 each uploads and downloads and lots more in free plan.

Related:
Show and Clear Android Notification Example
Adding Badge (Notification Count) to Android ActionBar Icon
Adding a Share Action to Android Application

Android Example: Android Push Notification Tutorial Using Firebase


Make sure you have installed Android Studio 1.4 and higher before creating new android project using android studio. Following are the simple steps to connect your android app/game to firebase to send/push notification to your app users.

Android Example: Android Push Notification Tutorial Using Firebase

1. Create a new Android Project using Android Studio


Create a new android project with the application name: Push Notification Example Using Firebase, company domain: viralandroid.com. Select the minimum SDK: API 14 Android 4.0(IceCreamSandwish) and empty activity.

2. Connect your Android App to Firebase


To connect your android app to firebase follow the following steps:

2.1. Go to Google Firebase Developer Console.

Push/Send Notification Tutorial Using Firebase in Android

2.2. Create a new project by clicking Create New Project button.
2.3. Add your application name in project name and select your country and click Create Project button. I have written Push Notification Firebase as project name.

Create New Project in Firebase to Send Notification/Message to the Users

2.4. After creating new project in firebase, you will see in the screen something like below.

Choose Platform in Firebase to Send Notification/Message to the Users

2.5. Click on the add firebase to your android app. Here you need to provide your application package name. After adding package name in the box click Add App button.
2.5. A file google-services.json is downloaded. Click continue and then finish button.

3. Adding google-services.json file to Your Android Application


3.1. Go to android studio. Switch to the project view in Android Studio, you will see project root directory.
3.2 Add google-services.json file that you just downloaded to your android app directory like the screenshot below.
Adding google-services.json file to Your Android Application Android Studio


4. Adding Google Services Plugin to Your Android Application


4.1. Open your project level build.gradle file and add classpath 'com.google.gms:google-services:3.0.0' as dependencies. Project level build.gradle file will look like below.

Project level build.gradle file

4.2. Now open your app level build.gradle file and add apply plugin: 'com.google.gms.google-services' and compile 'com.google.firebase:firebase-messaging:9.0.2' as dependencies. And then press Sync now. Following is the content of app level build.gradle file.

App level build.gradle file


5. Adding Internet Permission in your App AndroidManifest.xml File


Open your AndroidManifest.xml file and add android.permission.INTERNET as user permission. AndroidManifest.xml file will look like below.

AndroidManifest.xml

6. Sending a Notification/Message to your App Users from the Notifications Console


6.1. Go to Firebase Console.
6.2. Choose your project that we recently created.
6.3. Click Notification from left menu.

Sending a Notification/Message to your App Users from the Notifications Console

6.4. Click send your first message button, if you have not sent before.
6.5. Type your message in enter message area, enter message label, choose your app and click Send Message button. Review your message and click Send button.

Sending a Notification/Message to your App Users from the Firebase  Notifications Console

Run your Android Push Notification Tutorial Using Firebase application before sending above notification. Don’t open your application while sending notification. After rending notification to your android application users. Notification looks like below screenshot.

Android Push Notification Tutorial Using Firebase
Tutorial 5383502470569990148
Home item