Push Notifications

Below, we’ll show you how to send push notifications and/or push messages to your customers, with Firebase Cloud Messaging (FCM) in Intercom.

Step 1. Enable Google services for your app

If you already have a Firebase project with notifications enabled you can skip to the next step. Otherwise go to the FCM Console page and create a new project following these steps:

Give the project a name and click ‘Create Project’.

Once your project is set up, scroll down and select the ‘Cloud Messaging’’ card.

Click on the Android icon to continue setup.

Enter your app’s package name and click ‘Register App’.

Step 2. Setup client to receive push

Click the button "Download google-services.json" to download the config file. You’ll need to move that file into the same directory as your application level build.gradle.

Click "next" and then in your apps build.gradle you will need to add the following lines to your dependencies:

  1. groovy
  2. Kotlin
dependencies {
    implementation 'io.intercom.android:intercom-sdk:14.0.0'
    implementation 'com.google.firebase:firebase-messaging:23.1.+'
}

At the bottom of your build.gradle you must add:

apply plugin: 'com.google.gms.google-services'

It is important that this is at the very end of the file.

Click the Next button and then skip the verification step.

Step 3. Add your Server key to Intercom for Android settings

Finally, click the settings cog and select ‘Project settings’, then ‘Cloud Messaging tab’ and copy your Server key.

Open your Intercom app’s settings and select ‘Installation -> Android’. Then find the ‘Enable Push Notifications’ section. Here you'll be able to paste and save your Server API key.

Step 4. Setting your FCM icon (Optional)

If you want to add a custom icon for your notifications, just add an image named intercom_push_icon.png to each of your supported densities. Please note that vector drawables cannot be used here. For example:

/res/drawable-xxhdpi/intercom_push_icon.png
/res/drawable-xhdpi/intercom_push_icon.png
/res/drawable-hdpi/intercom_push_icon.png
/res/drawable-mdpi/intercom_push_icon.png

👍 Notifications icon design guidelines

We recommend following these material design guidelines for producing this icon.

Step 5. Disable push on log out

To stop users from receiving push messages when they have logged out of the app make sure to call:

  1. Kotlin
  2. Java
Intercom.client().logout()

Step 6. Using Intercom with other FCM setups (Optional)

The Intercom android sdk already comes with a default implementation of FirebaseMessagingService. This provides default implementations for onNewToken and onMessageReceived for FCM to work with Intercom. This step can be skipped if your app uses only Intercom for Push Notifications

If your application uses FCM for your own content, or if you use a third party service for FCM. You’ll need to update your FirebaseInstanceIdService and FirebaseMessagingService.

You should have a class that extends FirebaseMessagingService or the now deprecated FirebaseInstanceIdService. That service is where you get the device token to send to your backend to register for push. To register for Intercom push set it up like this:

  1. Kotlin
  2. Java
private val intercomPushClient = IntercomPushClient()

override fun onNewToken(refreshedToken: String) {
    intercomPushClient.sendTokenToIntercom(application, refreshedToken)
    // DO HOST LOGIC HERE
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
    val message = remoteMessage.data
    if (intercomPushClient.isIntercomPush(message)) {
     intercomPushClient.handlePush(application, message)
    } else {
        // DO HOST LOGIC HERE
    }
}

Troubleshooting tips

If you’re having trouble getting FCM to work in your app, here's a list of things you should check:

  • Make sure to tick the 'Send a push notification' box when you send a manual message.
  • Check that the notifications are not disabled for your app on your test device. Settings > Sound & Notification > App notifications. This may differ depending on the Android version.
  • Did you specify the correct Push Server API key?
  • Make sure you added your google-services.json file in the correct directory.

And as always, you can contact us via Intercom. We're always here to help 😀

Step 7. Open Intercom conversations from FCM

When a user taps on a push notification we hold onto data such as the URI in your message or the conversation to open. When you want Intercom to act on that data, just call:

  1. Kotlin
  2. Java
Intercom.client().handlePushMessage()

📘 Note

It’s important to wait for any splash screens or loading screens to finish before calling handlePushMessage or your users might not have time to see the conversation we opened.

If you wish to create a custom back stack for this notification you can pass a TaskStackBuilder to the same method:

  1. Kotlin
  2. Java
handlePushMessage(stackBuilder)