Building Android push notifications with Firebase and Courier’s SDK
7 min readMar 23


Push notifications have become an essential part of modern mobile apps, allowing you to keep your users engaged and informed. However, implementing push for different platforms can be a complex and time-consuming task, requiring developers to set up and handle token management, testing, and other logistical details.

Courier’s Android Mobile Notifications Software Development Kit (SDK) is designed to make it easy for you to implement push notifications in your mobile apps. The SDK provides a set of tools that simplify the process of managing user state, handling tokens, and sending test notifications. Some of these terms may be unfamiliar, but we’ll explain them in this article and show you how to use the SDK. Before diving into how to use the Courier Android SDK, first let’s touch on the benefits it provides. Later, we will go into more depth.

  • Manage tokens easily: The SDK simplifies the process of handling tokens, which can be a complex and time-consuming task for developers to set up and manage. When implementing push notifications, developers need to handle token management, which involves generating and storing unique identifiers for each device that can receive notifications.
  • Manage user state effectively: The SDK also simplifies the process of managing user state, which refers to the current status or context of a user within an app.
  • Send test notifications: The SDK includes tools that enable developers to send test notifications, ensuring that their notifications are working as intended before they go live. This can save time and prevent potential issues.

By providing these tools, the Courier Android SDK helps developers streamline the process of implementing push notifications in their apps. With these benefits in mind, let’s move on to how to get started with the SDK.

Getting started with Courier

To get started with the Courier Android SDK, you will need to have the following:

  1. Android Studio or any other development environment that supports Android development. The SDK supports Java, Kotlin, and Firebase Cloud Messaging.
  2. A valid Firebase project. Although the Courier SDK itself doesn’t need a Firebase account, if you want to send push notifications to your app you will need a Firebase account.
  3. A physical Android device for testing. Testing push notifications with or without the Courier SDK does not work well with emulators.
  4. A Courier account. You need an account in order to use the SDK.
  5. The SDK. Once you have the other prerequisites, you can download the SDK and include it in your project.

To install the Courier Android SDK have a look at the step-by-step guide on our GitHub page.

Once you’ve successfully set up the Courier SDK in your Android app, let’s dive into some of the features of the SDK.

A note to the developers amongst you: Some of the functions that we will cover below depend on an AppCompatActivity, just something to keep in mind as we move forward.

Managing user state

Before we think about sending notifications, it’s important to consider the user state. This is the status of a user in relation to your app, e.g., signed in or out. This can impact the user’s experience with your app. For instance, if your user is signed out, they shouldn’t be receiving notifications as if they are still signed in. For an optimal user experience, it’s best to keep the user’s push notification tokens in sync with their state. Most of this is handled automatically by Courier. In order to manage the user state in your app, you can use the functions provided by Courier. By calling the Courier.shared.signIn() function, you can ensure that the user's push notification tokens and their state are kept in sync.

accessToken = authKey_or_accessToken,
userId = userId

The accessToken can either be a Courier Auth Key used during development or a JWT (JSON Web Token) that should be used in your production app.

When the user signs out, you can use the Courier.shared.signOut() function to clear their state.


By following these steps, the FCM (Firebase Cloud Messaging) tokens on Android will be automatically synced to Courier, making it easier for you to manage the user’s state and send relevant and timely push notifications.

Push notification permissions

To make a great user experience, you’ll need to request push notification permissions at the right time in your user’s flow. Finding the code to request these permissions can be difficult. . Courier makes it easy to check permissions with the requestNotificationPermission() function.

if (requestNotificationPermission()) {
//Send some notification

The requestNotificationPermission() function returns a Boolean that tells us if the user has permissions on or off. Then, you can continue with your code, perhaps sending a test notification to the device to make sure everything is working well for the user experience you are building. In newer versions of Android (version 33 and up) this will present a popup asking your users for push notifications permissions. In older versions of android, this will always return true.

Simple delivery tracking

Courier has an onPushNotificationDelivered() function, which is triggered when a push notification is delivered to the device. This is useful for keeping track of delivery status.

override fun onPushNotificationDelivered(message: RemoteMessage) {

Bear in mind that this function will only be triggered when the app is in the foreground or potentially background state. It will not be called when the app is in the “killed” or “not running” state. It also must be inside of a CourierActivity (which is a subclass of AppCompatActivity).

Message received?

You know how to check if the notification was delivered, but what if you want to know when the user interacts with it? That’s where the onPushNotificationClicked() function comes in. This function is triggered when the user taps on a push notification. You can use this function to handle what happens when the user interacts with the notification and must also be inside of a CourierActivity (which is a subclass of AppCompatActivity)

override fun onPushNotificationClicked(message: RemoteMessage) {

In the example above, we are simply printing a message, but you can replace it with your own logic such as opening a specific activity or displaying some interface component.

Sending a test push

With permissions handled, and some understanding of how we can track the status of our notifications, lets see how sending notifications works. Courier enables you to send push notifications directly to a user’s ID via the SDK, without the need to make a direct call to Firebase from your backend or through a raw HTTP call. This ID is the userId you register data with in Courier. This should probably match the user IDs you use in your existing authentication system. For now, let’s look at how you can use the sendPush() function to send test push notifications. Here's how to send a test push.

val messageId = Courier.shared.sendPush(
authKey: 'a_courier_auth_key_only_for_testing',
userId: 'example_user',
title: 'Hello!',
body: 'This is a push message from Courier 🐣',
providers: [CourierProvider.fcm],

This code will send a push notification to every valid token for the given userId and providers (e.g., FCM) that you declare. So be careful and make sure to only use it for testing purposes. It’s important to note that the authKey you use in this example is for testing purposes only and should not be used in production.

Let’s talk about tokens

One of the most challenging aspects of push notifications is managing tokens: unique identifiers that are used to identify a specific device for push notifications. They are typically generated and managed by the operating system’s push notification service, such as Firebase Cloud Messaging (FCM) for Android and Apple Push Notification Service (APNS) for iOS. To send push notifications to a specific device or user, you must use the device’s token. Your app needs to store tokens securely on the back end and associate them with the relevant user or device. Additionally, tokens should be regularly updated, as they can change or expire. Token management also includes handling token deletion when a device or user unsubscribes from push notifications or uninstalls the app. Setting up your own token management infrastructure can require iteration between front-end (or mobile) and back-end developers. This back-and-forth can take several days or even a month, between designers, mobile engineers building the functionality into the app, and then the back-end engineer building the infrastructure to make it work. Courier takes care of all of the above for you! You don’t need to learn all the logistics of token management, because Courier’s mobile SDKs automatically takes push notification tokens, stores them in Courier, and automatically invalidates tokens that expire, allowing you to focus on building your product.


In this post you have seen how Courier streamlines the hassle of handling push notifications. It takes care of token generation, storage, and removal, allowing you to concentrate on building your app without worrying about the technicalities of token management. You’ve seen how the SDK is user-friendly, with a straightforward setup and integration process that can be completed with just a few lines of code, even in existing projects. Courier has other SDKs available. Whether you’re working with Android, iOS, React Native or Flutter, Courier has an SDK that can help streamline your push notification process. So, if you’re looking for a way to simplify your push notification management, give Courier a try.



Courier is the fastest way for developers to build notifications for their apps. With one API and easy-to-use UI trigger multi-channel notifications at scale.

Recommended from Medium


See more recommendations