Deal with it: Push notifications in Android using FCM
What is Firebase Cloud Messaging?
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages.
How to set up a FCM project on Firebase Console?
You need to create a Firebase project in the Firebase console.

After creating a project, it’s important to enter the package name your app is using.


After adding Firebase to your Android app, you’ll get a google-services.json. Please copy this into your project’s app folder.

Once all these configuration steps done, you can ready to develop the Android app.
How to set up a FCM Client App on Android?
To use FCM in Android, you have to add Firebase to your app and modify your gradle files.
At the project level gradle file, you need to add google-services as a classpath.
classpath 'com.google.gms:google-services:3.0.0'
At the app level gradle file, first you need to define google-services plugin at the top of gradle file.
apply plugin: 'com.google.gms.google-services'
After defining plugin, you need to add firebase-messaging as dependency.
//fcm
compile 'com.google.firebase:firebase-messaging:9.4.0'
How to get a Registration token?
Define a background service that requests the InstanceID token which identifies the application to the FCM server.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
How to handle incoming FCM messages and show as Notification?
Define a background service that handles incoming FCM messages.
public class MessagingService extends FirebaseMessagingService
To handle data messages override the onMessageReceived.
Don’t forget to add these service you created to your Android Manifest file.
<service
android:name=".service.MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".service.RegistrationIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
That’s it! FCM is all ready to receive messages.

Worth to mention;
I created a project that demonstrates how simplified and easy to use firebase is.
FirebaseTraining - This is an example project that demonstrates how simplified and easy to use firebase is.github.com
If you are interested in the topic, feel free to subscribe or to follow me onTwitter! If you like the article, click on the little heart at the bottom to recommend it and feel free to share it :-)
Resources: