Skip to content
Last updated

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 serviceThis 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 activityThe SDK delivers payloads as a JSON string in the payload extra.

private fun handleNotificationIntent(intent: Intent?) {
    intent?.getStringExtra("payload")?.let { json ->
        val notification = Gson().fromJson(
            json,
            NotificationRouter.DomainNotification::class.java
        )
        ModalFragment.newInstance(notification)
            .show(supportFragmentManager, "notification_modal")
    }
}

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.

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.