Push notifications

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

This page is part of a setup flow for the SDK. 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 --> test-support(Write tests) push --> test-support rich-push --> test-support identify -.-> in-app(Receive in-app) in-app --> test-support 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 register-token href "/docs/sdk/android/push" click push href "/docs/sdk/android/push" click rich-push href "/docs/sdk/android/rich-push" click in-app href "/docs/sdk/android/in-app" click test-support href "/docs/sdk/android/test-support" 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.

 Check out our sample app!

Our Remote Habits app, provides a real-world example and can act as a template to help you implement the SDK.

How it works

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

  1. Set up FCM.
  2. Set up push.
  3. Identify a person. When someone starts the app, they automatically generate a device token. Identifying the person associates the device token with the person in Customer.io, 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

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

    implementation 'io.customer.android:messaging-push-fcm:<version-here>'
    
  2. Initialize the push module. The push module has an optional config object, explained below. See rich push for help configuring the push module to deep links.

     CustomerIO.Builder(
         siteId = "siteId",
         apiKey = "apiKey",
         appContext = application,
     ).apply {
         addCustomerIOModule(
             ModuleMessagingPushFCM()
         )
         autoTrackScreenViews(true)
         setRequestTimeout(8000L)
         setRegion(Region.US)
         build()
     }

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

However, 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(message)
    if (handled) {
        logger.breadcrumb(this, "Push notification has been handled", null)
    }
 }
 
override fun onNewToken(token: String) {
    CustomerIOFirebaseMessagingService.onNewToken(token)
}

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.

Push module configuration

ModuleMesagingPushFCM has an optional configuration object.

The notificationCallback is A callback that notifies client on push notification related actions. For now, this callback is only useful for handling deep links, but we have plans to add more methods in future releases. It defaults to null.

The redirectDeepLinksToOtherApps flag enables (true) or disables (false) the ability to open non app links outside the app. It is true by default.

  • true: links not supported by your app will be opened in other matching apps. If a matching app isn’t found, the host app opens to default landing page.
  • false: unsupported links open the host app to its default landing page.
CustomerIO.Builder(
    siteId = "siteId",
    apiKey = "apiKey",
    appContext = application,
).apply {
    addCustomerIOModule(
        ModuleMessagingPushFCM(
            config = MessagingPushModuleConfig.Builder().apply {
                setNotificationCallback(this)
                setRedirectDeepLinksToOtherApps(false)
            }.build()
        )
    )
    setRegion(Region.US)
    build()
}

Capture push metrics

Customer.io supports three device-side metrics that help you determine the efficacy of your push notifications: delivered, opened, and converted.

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
)
Copied to clipboard!
Latest release
 3.1.1
Is this page helpful?