Android Push Notifications

This is a tutorial on how to add push notifications to your Android app with Firebase Cloud Messaging (FCM) from scratch.

Package name is important here to configure Firebase later.
This package name needs to be the same as the one in your Android project
At the project level build.gradle , add the classpath and click “Sync Now”
classpath ''
At the app level build.gradle , add the lines as shown and click “Sync Now”
apply plugin: ''implementation platform('')implementation ''
implementation ''
<action android:name="" />
class MyFirebaseMessagingService : FirebaseMessagingService(){
override fun onMessageReceived(remoteMessage: RemoteMessage) {
Log.d(TAG, remoteMessage.toString())
Added a button and a multi line text
val btn = findViewById( as Button
val txt = findViewById ( as EditText
btn.setOnClickListener {
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
(!task.isSuccessful) {
Log.w(TAG, "Fetching FCM registration token failed", task.exception)

// Get new FCM registration token
val token = task.result

// Log and toast
Log.d(TAG, token)
You’ll need this FCM registration token to send push notifications to this device

Set up a Firebase Cloud Messaging client app on Android

< Back to all the stories I had written

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store