Push notifications

Get started setting up push notifications for Android. Our Android SDK supports push notifications over FCM.

 Our mobile SDKs are in alpha and subject to change

While we’re very excited about our mobile SDKs, they’re still works in progress! If you want to try them out, contact product@customer.io

This page is part of an introductory series to help you get started with the essential features of our SDK. The highlighted step(s) below are covered on this page. Before you continue, make sure you've implemented previous features—i.e. you can't identify people before you initialize the SDK!

graph LR getting-started(Install SDK) -->B(Initialize SDK) B --> identify(identify people) identify -.-> track-events(Send events) identify -.-> push(Receive push) identify -.-> rich-push(Receive Rich Push) track-events --> testing-error-handling(handle errors) push --> testing-error-handling rich-push --> testing-error-handling click getting-started href "/docs/sdk/android/getting-started" click B href "/docs/sdk/android/getting-started/#initialize-the-sdk" click identify href "/docs/sdk/android/identify" click track-events href "/docs/sdk/android/track-events/" click push href "/docs/sdk/android/push" click rich-push href "/docs/sdk/android/rich-push" click testing-error-handling href "/docs/sdk/android/testing-error-handling" style push fill:#B5FFEF,stroke:#007069

Before you begin

This page explains how to receive push notifications using our SDK. However, before you can send push notifications to your audience, you need to enable Customer.io to send push notifications through Firebase Cloud Messaging (FCM).

This process lets you receive basic push notifications in your app—a title and a message body. To send a notification with an image, link, etc, complete the process on this page, and then see our rich push documentation.

How it works

Before a device can receive a push notification, you must:

  1. Set up FCM.
  2. Implement the messaging-push-fcm SDK.
  3. Identify a person. This associates a push token with the person, so that they can receive push notifications.
  4. Set up a campaign to send a push notification through the Customer.io composer.

Set up push

You must implement the Push Messaging SDK to use push notification features.

implementation 'io.customer.android:messaging-push-fcm:<version-here>'

The SDK adds a FirebaseMessagingService to the app manifest automatically, so you don’t have to perform additional setup to handle incoming push messages.

If your application implements its own FirebaseMessagingService, make sure that when you call onMessageReceived and onNewToken methods, you also call CustomerIOFirebaseMessagingService.onMessageReceived and CustomerIOFirebaseMessagingService.onNewToken respectively.

class FirebaseMessagingService : FirebaseMessagingService() {

 override fun onMessageReceived(message: RemoteMessage) {
    val handled = CustomerIOFirebaseMessagingService.onMessageReceived(this, message)
    if (handled) {
        logger.breadcrumb(this, "Push notification has been handled", null)
    }
 }
 
override fun onNewToken(token: String) {
    CustomerIOFirebaseMessagingService.onNewToken(token) { result ->
            when (result) {
                is ErrorResult -> {
                    // Handle error
                }
                is Success -> {
                    // Handle success
                }
            }
        }
    }
}

Push notifications launched from the SDK are currently posted to our default channel—[your app name] Channel. In the future, we plan to let you customize channels/categories so that users can subscribe and unsubscribe to content categories as necessary.

Capture push metrics

You must configure your app to report device-side metrics back to Customer.io when people interact with your messages. Customer.io supports three device-side metrics: delivered, opened, and converted. You can find more information about these metrics in our push developer guide.

By default, the messaging-push-fcm SDK automatically tracks opened and delivered for push notifications originating from Customer.io. Otherwise, you can track push metrics with the trackMetric method.

CustomerIO.instance().trackMetric(
    deliveryID = deliveryId,
    deviceToken = deliveryToken,
    event = MetricEvent.delivered
).enqueue { result ->
    when (result) {
        is ErrorResult -> {
            // Handle error
        }
        is Success -> {
            // Handle success
        }
    }
}
Copied to clipboard!