> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase Cloud Messaging

> Send native push notifications with Firebase Cloud Messaging and manage permissions, tokens, topics, channels, and badges from your web app.

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.

> [!TIP]
>
> **Developer Demo**
>
> Display our demo page in your app to test during development: [https://median.dev/firebase-messaging](https://median.dev/firebase-messaging)
>
> The demo also links to a standalone [Test Sender](https://median.dev/firebase-messaging/sender.html). 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](https://docs.median.co/docs/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](https://docs.median.co/docs/javascript-bridge.md) 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](https://console.firebase.google.com/), 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](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/e16132209cfe5298ccd9c00fa4ed7895fd3aa96cd31d32cfb6298a930e3f2eb0-Screenshot_2026-08-26_at_11.29.36.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=37f30cc8f87a5e9a7ad0860ebb62111a)

App Studio Google Services configuration

4. Enable the **Firebase Cloud Messaging** native plugin.
5. Configure plugin settings.
6. Rebuild your app to include the Firebase Cloud Messaging SDKs and your settings.

![Firebase Cloud Messaging plugin settings in App Studio](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/fffe6acce36437b899ed317316a4f8ee2b313fb09b2f390467d0af42f54ae7f1-Screenshot_2026-08-26_at_11.28.21.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=d4800be0c1a16c7a7d16e4857fd15156)

App Studio Firebase Cloud Messaging configuration

#### Plugin configuration options

| Setting | Required | Description |
| - | - | - |
| Automatic Registration | No | Controls whether a device token is requested automatically on launch, or only after `requestPermission()` is called explicitly. |
| Show Foreground Notifications | No | By default, push notifications are suppressed when your app is open and in focus. This is useful for sensitive and urgent notifications such as chat messages and delivery notifications. |

> [!NOTE]
>
> **Rebuild after configuration**
>
> Plugin 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](https://docs.median.co/docs/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.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.requestPermission({
  callback: function (result) {
    console.log("Permission granted status:", result.granted); // true or false
  }
});
```

**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.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.checkPermission({
  callback: function (result) {
    console.log("Are notifications enabled?", result.granted); // true or false
  }
});
```

#### Token management

**Register**

Registers the device with FCM if no token exists yet.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.register({
  callback: function (result) {
    console.log("Registered, token:", result.token);
  }
});
```

**Get token**

Returns the current FCM registration token for the device, if one has been generated. Maps to the demo's **Get Token** button.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.getToken({
  callback: function (result) {
    console.log("FCM token:", result.token);
  }
});
```

> [card] [Looking to send pushes to individual users or segments?](https://docs.median.co/docs/fcm-identifying-targeting-users.md)
>
> 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.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.deleteToken({
  callback: function (result) {
    console.log("Token deleted:", result.success);
  }
});
```

#### 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**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.subscribeToTopic({
  topic: "breaking_news",
  callback: function (result) {
    console.log("Subscribed:", result.success);
  }
});
```

**Unsubscribe from a topic**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.unsubscribeFromTopic({
  topic: "breaking_news",
  callback: function (result) {
    console.log("Unsubscribed:", result.success);
  }
});
```

**List subscribed topics**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.getSubscribedTopics({
  callback: function (result) {
    console.log("Subscribed topics:", result.topics); // e.g. ["breaking_news"]
  }
});
```

#### 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**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.createChannel({
  channelId: "order_updates",
  channelName: "Order Updates",
  importance: "high", // "high" | "default" | "low" | "min"
  callback: function (result) {
    console.log("Channel created/updated:", result.success);
  }
});
```

**Delete a channel**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.deleteChannel({
  channelId: "order_updates",
  callback: function (result) {
    console.log("Channel deleted:", result.success);
  }
});
```

**List channels**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.getChannels({
  callback: function (result) {
    console.log("Channels:", result.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**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.setBadge({
  count: 4,
  callback: function (result) {
    console.log("Badge set:", result.success);
  }
});
```

**Clear badge**

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseMessaging.clearBadge({
  callback: function (result) {
    console.log("Badge cleared:", result.success);
  }
});
```

#### 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.

Median JavaScript Bridge

```javascript JavaScript theme={null}
// Show a native banner for pushes received while the app is open
median.firebaseMessaging.enableForegroundBanners();

// Suppress the native banner; the notificationReceived listener still fires
median.firebaseMessaging.disableForegroundBanners();
```

#### 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.

Median JavaScript Bridge

```javascript JavaScript theme={null}
// Triggers when a push notification is delivered while the app is active
const receivedListenerId = median.firebaseMessaging.notificationReceived.addListener((data) => {
console.log("Notification received:", data);
});

// Triggers when a push notification is tapped by the user
const clickedListenerId = median.firebaseMessaging.notificationClicked.addListener((data) => {
console.log("Notification tapped:", data);
});

// Remove a listener when it's no longer needed
median.firebaseMessaging.notificationReceived.removeListener(receivedListenerId);
```

## Testing checklist

Use this checklist, together with the [demo page](https://median.dev/firebase-messaging) and [test sender](https://median.dev/firebase-messaging/sender.html), 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

> [accordion] App Studio reports missing Google services configuration files
>
> FCM requires Google Services to be configured for your app. Follow the steps in our [Google Services guide](https://docs.median.co/docs/google-services.md) to add `google-services.json` (Android) and `GoogleService-Info.plist` (iOS).

> [accordion] Test push from the sender isn't arriving
>
> 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.

> [accordion] Deep links open in the browser instead of the app
>
> Configure Median [deep linking](https://docs.median.co/docs/deep-linking) (URL scheme, Universal
> Links, and App Links) so the target URL in your FCM payload matches a route
> the app handles.

> [accordion] Custom notification sound doesn't play (Android)
>
> 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:
>
> ```json FCM message theme={null}
> {
>   "message": {
>     "token": "<device token>",
>     "notification": { "title": "Order shipped", "body": "Your order is on its way" },
>     "android": {
>       "notification": { "channel_id": "order_updates", "sound": "order_chime" }
>     }
>   }
> }
> ```
>
> 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.
>
> > [!NOTE]
> >
> > To use a different sound, send it on a new `channel_id`. Messages without a `channel_id` use the default channel and its sound.

> [accordion] Tapping grouped notifications doesn't open the target URL (Android)
>
> 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.

> [accordion] Badge count isn't showing (Android)
>
> 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.


## Related topics

- [Targeting users with Firebase Cloud Messaging](https://docs.median.co/docs/fcm-identifying-targeting-users.md)
- [Push notifications overview](https://docs.median.co/docs/push-notifications-overview.md)
- [OneSignal overview](https://docs.median.co/docs/onesignal.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.