/ kotlin

Push Notifications using FCM

Firebase cloud messaging is cross platform which supports Android, iOS and mobile wep applications.

Create new android studio project.

Log in to FCM console. Create or Add a project.

Screen-Shot-2017-09-14-at-11.56.46-PM

Give the project name & select the country

Screen-Shot-2017-09-14-at-11.58.52-PM

Select "Add Firebase to your android app"

Screen-Shot-2017-09-15-at-12.01.01-AM

Give your app package name and click on Register App.

Screen-Shot-2017-09-15-at-12.02.16-AM

Then you will receive google-services.json file.

Navigate to android app folder and paste google-services.json.

Screen-Shot-2017-09-15-at-12.08.22-AM

Add the following code to the root level build.gradle file.

Screen-Shot-2017-09-15-at-12.13.46-AM
In the app level build.gradle add the plugin for google-services

Screen-Shot-2017-09-15-at-12.12.00-AM
Declare Activity & intent fliters to AndroidManifest.xml

Screen-Shot-2017-09-15-at-12.25.07-AM
Create a class called FirebaseIdService and get the registration token.

Screen-Shot-2017-09-15-at-12.16.06-AM
Add following lines of code to handle notification using Broadcast Receiver.

Screen-Shot-2017-09-15-at-12.18.43-AM
On Launch of MainActivity.kt register Broadcast receiver to check if we have any push notifications and unregister to release the resources. Also design the notification style.

Screen-Shot-2017-09-15-at-12.21.20-AM

From FCM console, select the created app
Select Notifications option from navigation menu.

Screen-Shot-2017-09-15-at-12.27.58-AM-1

Then select New Message and enter the message title and content and finally click on Send Message buton.

Screen-Shot-2017-09-15-at-12.30.53-AM
Screen-Shot-2017-09-15-at-12.38.10-AM

Ramya Gangula

Ramya Gangula

I work as Android developer at GM financials. Before GM i worked at Samsung. The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way

Read More