Push Notifications

Register FCM tokens with Superwall, manage device notification preferences, and measure notification opens from your Android app.

Register your app's Firebase Cloud Messaging (FCM) token with Superwall so it can send push notifications to the device. Use this when integrating Superwall notification campaigns with an existing Android notification flow.

Requirements

  • Superwall Android SDK 2.10.0 or later.
  • FCM configured in your app and Superwall notifications enabled for your app.
  • Call Superwall.configure before using Superwall.instance.

The SDK has no Firebase dependency and does not request notification permission for this integration. Your app owns Firebase setup and permission requests.

Register the device token

After configuring Superwall, retrieve the current token at startup:

import com.google.firebase.messaging.FirebaseMessaging
import com.superwall.sdk.Superwall

FirebaseMessaging.getInstance().token.addOnSuccessListener { token ->
    Superwall.instance.setPushToken(token)
}

Also forward new tokens from FirebaseMessagingService.onNewToken. If the service can run before your app configures Superwall, persist the token in your app and forward it after configuration; accessing Superwall.instance before configuration throws.

// Only when Superwall is already configured:
override fun onNewToken(token: String) {
    Superwall.instance.setPushToken(token)
}

It's safe to register on every launch. The SDK sends changes to the token, notification permission, device preference, or user identity, and otherwise refreshes unchanged state at most once a day. Notification permission is checked again when the app enters the foreground.

Manage notification preferences

Devices are opted in by default. Use these methods to change the device's preference for Superwall notifications:

Superwall.instance.optOutOfNotifications()
Superwall.instance.optInToNotifications()

The preference survives app launches, reset(), and identify(userId). It does not change the Android system notification permission.

Measure notification opens

Pass the intent that opened your Activity from a notification tap to Superwall, for example from onCreate or onNewIntent after configuration:

Superwall.instance.handleNotificationOpen(intent)

For notifications FCM displays itself, the tap intent already carries the data keys. If your app builds its own notification in onMessageReceived, copy the sw data value to the intent used by its tap PendingIntent:

val tapIntent = Intent(this, MainActivity::class.java)
    .putExtra("sw", message.data["sw"])

If your tap handler has the notification's data map instead, use:

Superwall.instance.handleNotificationOpen(data) // Map<String, String>

Call these methods only when the user taps a notification. Calling them on delivery in onMessageReceived would count deliveries as opens. Notifications not sent by Superwall are ignored.

Limitations

Token registration is retained locally until Superwall notifications are enabled for the app. Nothing is sent while eventTrackingBehavior is NONE. The token travels only to Superwall's servers; it does not appear in delegate analytics callbacks, delegate logs, user attributes, or audience filters.

How is this guide?

On this page