Mobile Development

FCM Notifications With API 26+ With Reverse Compatibility

With the release of API 26 (Android Oreo), FirebaseInstanceIdService was deprecated and notifications now require notification channels to work...

Ali Elias - Lead Backend Developer

Sep 16, 2019

With the release of API 26 (Android Oreo), FirebaseInstanceIdService was deprecated and notifications now require notification channels to work. I’ll be showing you how to set up FCM(Firebase Cloud Messaging) notifications for Android with for API 26+ and with reverse compatibility. All code will be provided in Kotlin. This is my first Medium article, so bear with me :)

In order to capture notifications from FCM, we need to set up a service for our app, namely an implementation of FirebaseMessagingService.

FCM targets devices by using encrypted, alpha numeric tokens that are unique to every device. They’re generated the first time you open up your app;

  • if the app deletes the token,

  • if the user installs then uninstalls, or

  • if the user clears their data.

FirebaseMessagingService will turn on automatically whenever a new token is generated for your device or when it picks up a notification from FCM. In order to pick up a FCM token, we have to override onNewToken in the FirebaseMessaginService.

Keep track of your FCM token that will be logged in your logcat, You’ll be needing it later to send notifications. If you ever lose it and need to retrieve it, you can use the following function to get your FCM token. We also need to register our service in the manifest and ask for internet permissions. API 26 now requires the use of notification channels, these channels can have different visual and auditory behaviors that users can modify in their notification settings.

All notification channels need to be named, so go ahead and name your channel. When a notification is sent to your device, the onMesssageReceived is triggered in the FirebaseMessagingService. In order to handle the notification and display it to the user, we need to override onMessageRecieved. We’ll be getting to buildNotificationChannel() and sendNotification() functions in a moment. Notification channels are only relevant for devices above API 26 so we need to have a statement that checks if the device in question is API 26+. The following code is an example of how you can build a notification channel. There are a number of different behaviors that you can manipulate for notification channels. A full list can be found at

In order to display a notification for the user we need to use NotificationCompat’s Builder class. Before API 26, once could use NotificationCompat.Builder(Context), but that has been deprecated in favor of NotificationCompat.Builder(ContextNotificationChannel) to accommodate notification channels.

For API 26+, we can build a notification in the following way: For devices lower than API 26: Putting it all together, we get: We check the API of the device to choose the appropriate way of building our notification. Notifications come with a number of customizable options, a full list can be found at Finally, we use notificationManager.notify() to display our notification to the user.

Your app is now ready to pick up notifications!

Let’s go ahead and test it out by heading over to the Firebase Console. Scroll down on the menu, select “Firebase Messaging” and create a new message. Grab your FCM token from your logs earlier, select “Single Device” in the console and paste your FCM token. Enter the text you want to display and press send!

Voila, you should see your device or emulator receiving the notification!

I hope this article was able to get you started with FCM notifications, thanks for your time. For more information on FCM for Android, visit

Continue Reading


Automate Your Business 7 Ways in 7 Days
Whether you are a head of a startup or a SME (Small/Medium Enterprise), automation is your friend. Think of automation like this...
Sep 16, 2019


Modern Brands That Use E-Commerce Really Well (Part I)
E-Commerce is an extremely powerful tool for any retail or brick and mortar business to invest in...
Sep 16, 2019


The Best Way to Define and Prioritize Features for Your MVP
Starting a business can be risky. Maybe you have a great business idea for a mobile app. Maybe you’ve done your market research to validate your concept...
Sep 16, 2019