B Bubbl Docs

Notifications and Modals

Bubbl delivers push notifications via FCM. Your app can show a modal when a notification is received or opened.

Step 1: Register the FCM service

This is already covered in the manifest section:

<service
    android:name="tech.bubbl.sdk.services.MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Why

Without this, notifications will never reach the SDK.

Step 2: Handle payloads sent to your activity

The SDK can deliver JSON in payload, notification_payload, or data.

private fun handleNotificationIntent(intent: Intent?) {
    val json = intent?.getStringExtra("payload")
        ?: intent?.getStringExtra("notification_payload")
        ?: intent?.getStringExtra("data")
        ?: return

    val notification = Gson().fromJson(
        json,
        NotificationRouter.DomainNotification::class.java
    )
    ModalFragment.newInstance(notification)
        .show(supportFragmentManager, "notification_modal")

    intent?.removeExtra("payload")
    intent?.removeExtra("notification_payload")
    intent?.removeExtra("data")
}

override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)
    handleNotificationIntent(intent)
}

Why

Notifications can open your activity or deliver content while your app is already open.

Duplicate Push Guard

From SDK 2.2.6, mixed notification + data pushes are deduped by the SDK.

  • Background/terminated: SDK suppresses extra local render if OS already renders.
  • Foreground: only one presentation path is used.

Use SDK-owned tech.bubbl.sdk.services.MyFirebaseMessagingService and avoid app-level replacement services unless explicitly debugging.

Step 3: Listen for in‑app broadcast payloads (optional)

private fun registerModalReceiver() {
    LocalBroadcastManager.getInstance(this).registerReceiver(
        modalReceiver,
        IntentFilter(NotificationRouter.BROADCAST)
    )
}

Why

This allows the SDK to deliver payloads while the app is running, even if it did not open the activity.

Tooltip

If you do not want to show modals, you can ignore the payload and just let the system notification appear.