Skip to main content
The Firebase Cloud Messaging plugin enables native mobile push notifications by integrating the official Firebase Cloud Messaging SDKs directly on iOS and Android without the need for a third-party customer engagement platform. Median handles native SDK setup, token lifecycle, notification channels, and badge/foreground behavior, and exposes it all to your web app through the Median JavaScript Bridge. This guide covers Firebase project setup, Median App Studio configuration, and the Median JavaScript Bridge APIs used to manage permissions, tokens, topics, notification channels, and incoming push events.
Developer DemoDisplay our demo page in your app to test during development: https://median.dev/firebase-messagingThe demo also links to a standalone Test Sender. Run it in your browser (not inside the app) to send real test pushes to a device or topic using a Firebase service-account key. It supports presets for plain, deep-link, big picture/text, custom channel, badge, and silent notifications, and shows the raw FCM payload it sends.

Why use Firebase Cloud Messaging

  • Direct-to-device push, no middleman: Send native push notifications straight from your own Firebase project to iOS and Android devices inside the Median shell, giving you end-to-end control over the messaging pipeline.
  • Bridge-first control: Manage permissions, registration tokens, topic subscriptions, notification channels, and badge counts directly from JavaScript without writing native code.
  • Topic-based targeting: Subscribe and unsubscribe devices from FCM topics to broadcast messages to segments of users without maintaining a token list yourself.
  • Notification channel management (Android): Create, update, and delete notification channels directly from your web app.
  • Foreground notification control: Choose whether incoming pushes show a banner while the app is open, or are delivered silently to your JavaScript listeners instead.
  • Deep linking: When deep linking is configured, notification taps can open the right screen in-app instead of the device browser.

Prerequisites

  • A Median app with the JavaScript Bridge enabled.
  • A Firebase project with Cloud Messaging enabled.
  • google-services.json uploaded in your Median app configuration (required for push delivery on Android).
  • GoogleService-Info.plist uploaded in your Median app configuration, plus an APNS authentication key or certificate configured in the Firebase console (required for push delivery on iOS).

Implementation guide

Firebase project setup

Create (or reuse) a Firebase project and register your Android and iOS apps to it. Median handles native SDK initialization once those configuration files and credentials are in place.
  1. In the Firebase console, create a project (or select an existing one) and enable Cloud Messaging.
  2. Add an Android app to the project using your app’s package name/Application ID, then download the generated google-services.json.
  3. Add an iOS app to the project using your app’s Bundle ID, then download the generated GoogleService-Info.plist.
  4. In Project settings → Cloud Messaging → Apple app configuration, upload an APNS authentication key (recommended) or certificate so Firebase can deliver to iOS devices.

App configuration

  1. Open Median App Studio for your app.
  2. Navigate to Build & Deploy.
  3. Upload google-services.json (Android) and GoogleService-Info.plist (iOS) in Google Services configuration.
Google Services section in Build & Deploy with upload fields for google-services.json and GoogleService-Info.plist

App Studio Google Services configuration

  1. Enable the Firebase Cloud Messaging native plugin.
  2. Configure plugin settings.
  3. Rebuild your app to include the Firebase Cloud Messaging SDKs and your settings.
Firebase Cloud Messaging plugin settings in App Studio

App Studio Firebase Cloud Messaging configuration

Plugin configuration options

Rebuild after configurationPlugin settings take effect only in new builds. After changing credentials or uploading new Firebase configuration files, rebuild your app and test on a real device or simulator before releasing.

Deep linking (optional)

The Firebase Cloud Messaging plugin integrates with Median deep linking. When deep links are configured, users who tap a push notification are routed to the correct screen inside the app rather than to the mobile browser. The Test Sender’s Deep link preset lets you validate this by sending a push with a target URL. To enable this:
  1. Configure URL schemes, Universal Links (iOS), and App Links (Android) in Median App Studio.
  2. Ensure the target URL sent in your FCM payload matches the routes handled inside your app.

JavaScript Bridge functions

All methods are available on the median.firebaseMessaging namespace and must be called after the Median JavaScript Bridge is fully initialized.

Push notification permissions

Request permission Triggers the native OS permission prompt. Maps to the demo’s Request Permission button. For best results, defer this call to a point in the user journey where the value of notifications is clear. Contextual prompts have significantly higher opt-in rates. On Android 12 and below, notification permission may be granted automatically depending on device OS version and policy.
Check permission status Returns whether the user has currently granted or denied notification permission at the OS level. Maps to the demo’s Check Permission button.

Token management

Register Registers the device with FCM if no token exists yet.
Get token Returns the current FCM registration token for the device, if one has been generated. Maps to the demo’s Get Token button.

Looking to send pushes to individual users or segments?

Follow the guide below to identify and target individual users or segments.
Delete token Deletes the current FCM registration token, for example on sign-out, to stop notifications from being delivered to a device that is no longer associated with the signed-in user.

Topics

Subscribe or unsubscribe a device from FCM topics to target groups of users without maintaining your own list of device tokens. Subscribe to a topic
Unsubscribe from a topic
List subscribed topics

Notification channels (Android)

Android groups notifications into channels that control importance, sound, and visual treatment. Once a channel is created, only its name and description can be changed. The channel ID and importance are fixed for the life of the channel. Create or update a channel
Delete a channel
List channels

Notification badges

Sets the app icon badge count. This is best-effort: it works on launchers that support badges (e.g. Samsung, Xiaomi, and similar), and does nothing on stock Android launchers that don’t support badge counts. Set badge
Clear badge

Foreground notifications

Controls whether an incoming push shows a visible banner while the app is in the foreground. Turn banners off if you’d rather handle the incoming event yourself (e.g. show an in-app toast) without the OS notification also appearing.

Listeners

Register listeners to respond when notifications are received in the foreground or tapped by the user. Multiple listeners can be registered for the same event. Each listener fires independently until it’s removed.

Testing checklist

Use this checklist, together with the demo page and test sender, to confirm Firebase Cloud Messaging is working correctly in your app:
  • Configuration files present: google-services.json and GoogleService-Info.plist are uploaded in Median App Studio and the app has been rebuilt.
  • Permission flow: requestPermission() prompts the OS dialog and checkPermission() reflects the resulting status.
  • Token generated: getToken() returns a non-empty token on a real device.
  • Test push received: Using the Test Sender with your service account key, send a push to the copied token and confirm it’s received and, if tapped, opens the app.
  • Topics: Subscribe to a test topic, send a push to that topic from the Test Sender, and confirm delivery; then unsubscribe and confirm it stops.
  • Channels (Android): Create a custom channel, send a push targeting that channelId from the Test Sender, and confirm it uses the expected importance/behavior.
  • Badge: Set and clear a badge count and confirm it’s reflected on supported launchers.
  • Foreground banners: Toggle banners off and confirm the app still receives the notificationReceived event without showing a native banner while foregrounded.
  • Deep linking: Send a push using the Deep link preset and confirm the tap opens the correct in-app screen rather than the device browser.

Troubleshooting

FCM requires Google Services to be configured for your app. Follow the steps in our Google Services guide to add google-services.json (Android) and GoogleService-Info.plist (iOS).
Check that everything points to the same Firebase project:
  • The project ID in the Test Sender matches the project in your app’s google-services.json / GoogleService-Info.plist.
  • The service account key belongs to that same project.
  • The destination token or topic is current.
Device tokens can rotate. If it’s been a while, copy the token from the demo page again.
On Android, a notification’s sound belongs to its notification channel, not the individual message. To play a custom sound, set channel_id alongside sound in the message’s android.notification block:
FCM message
The first message sent with a new channel_id creates that channel with the given sound. Android doesn’t let apps change a channel’s sound after it’s created, so the channel keeps that sound permanently.
To use a different sound, send it on a new channel_id. Messages without a channel_id use the default channel and its sound.
When several notifications from your app are showing, Android may bundle them into a group. Tapping the group summary opens the app without a target URL. Expand the group and tap an individual notification to open its URL.
Badge counts are best-effort and depend on launcher support. They work on Samsung, Xiaomi, and similar launchers, but have no effect on stock Android (AOSP/Pixel-style) launchers. This is a platform limitation, not a problem with your integration.
Last modified on November 20, 2026