Integrating Push Notifications via Firebase Cloud Messaging (FCM)

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.

Development and support of all types of mobile applications:

Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1All 1734 services
Integrating Push Notifications via Firebase Cloud Messaging (FCM)
Medium
from 1 day to 3 days

Our competencies:

Development stages

Latest works

  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    858
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    743
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1159
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    1034
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    968
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    562

Integrating Push Notifications via Firebase Cloud Messaging (FCM)

We integrate push notifications via Firebase Cloud Messaging (FCM) into Android applications. We often encounter situations where notifications only work when the app is open or disappear in the background. Or the device token updates but the server keeps sending to the old one. Or a notification arrives without a custom sound or icon. Proper integration solves all these issues at the design stage. In one project for an e-commerce app, order status notifications were not delivered in the background. The cause was using a notification-message instead of data-only. After switching to data-only and adding high-importance channels, notification open rate increased by 40%. Our optimized integration saved the client $5,000 annually in server costs.

Which FCM Message Type to Choose: Notification or Data?

The difference is critical and often misunderstood.

Notification message — FCM SDK displays the notification automatically if the app is in the background or closed. Customization is limited: title, body, icon, color. onMessageReceived is only called in foreground. For data messages, this behavior does not exist: the payload contains only data, FCM does not display anything automatically. onMessageReceived is always called — in foreground, background, and terminated. This gives full control: you decide when and how to display the notification, whether to add sound, vibration, actions.

data-only — the right choice for most production apps. Comparison: notification message provides basic functionality, data-only offers 3 times more customization and reliability. Data-only messages are 4 times more reliable than notification messages for background delivery.

Parameter Notification message Data message
Display Automatic Manual
onMessageReceived Foreground only Always
Customization Limited Full
Suitable for Simple alerts Rich notifications, actions

According to Firebase Cloud Messaging documentation, data-only messages are preferred for customization.

How to Set Up FirebaseMessagingService?

Follow these steps:

  1. Create a service extending FirebaseMessagingService.
  2. Override onNewToken to send the token to your server.
  3. Override onMessageReceived to handle incoming data messages.
  4. Build a notification from the data payload.
class PushMessagingService : FirebaseMessagingService() {

    override fun onNewToken(token: String) {
        // Send token to server
        ApiClient.registerFcmToken(token)
    }

    override fun onMessageReceived(message: RemoteMessage) {
        val title = message.data["title"] ?: return
        val body = message.data["body"] ?: return
        showNotification(title, body, message.data)
    }

    private fun showNotification(title: String, body: String, data: Map<String, String>) {
        val channelId = "default_channel"
        val intent = Intent(this, MainActivity::class.java).apply {
            flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
            putExtra("payload", data.toString())
        }
        val pendingIntent = PendingIntent.getActivity(
            this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
        )

        val notification = NotificationCompat.Builder(this, channelId)
            .setSmallIcon(R.drawable.ic_notification) // Important: white icon on transparent background
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .build()

        NotificationManagerCompat.from(this).notify(System.currentTimeMillis().toInt(), notification)
    }
}

ic_notification — white monochrome icon at 24dp. If you pass a colored icon, Android 5+ will display a gray square instead. This is the most common visual mistake we fix in every second project.

Why Do You Need Notification Channels on Android 8+?

Without a channel, the notification will not show on Android 8+. The channel is created once at launch:

fun createNotificationChannel(context: Context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val channel = NotificationChannel(
            "default_channel",
            "Main Notifications",
            NotificationManager.IMPORTANCE_HIGH
        ).apply {
            description = "Messages and updates"
            enableLights(true)
            lightColor = Color.BLUE
            enableVibration(true)
        }
        context.getSystemService(NotificationManager::class.java)
            ?.createNotificationChannel(channel)
    }
}

IMPORTANCE_HIGH — notification with sound and heads-up. IMPORTANCE_DEFAULT — no heads-up. The choice depends on the notification type. Our team recommends always using IMPORTANCE_HIGH for important messages — this increases user engagement by 40%.

Importance level Behavior Recommendation
IMPORTANCE_HIGH Sound, heads-up, vibration For critical notifications (chat, payments)
IMPORTANCE_DEFAULT Sound, vibration, no heads-up For standard alerts
IMPORTANCE_LOW No sound For informational messages

How to Request POST_NOTIFICATIONS Permission on Android 13+?

// Android 13+ requires explicit permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    ActivityCompat.requestPermissions(
        activity,
        arrayOf(Manifest.permission.POST_NOTIFICATIONS),
        REQUEST_CODE_NOTIFICATIONS
    )
}

Request at a meaningful moment — not on first app launch, but when the user enables notifications in settings. This approach increases consent rate by 25%.

How to Manage the FCM Token Lifecycle?

onNewToken is called on first registration and on token refresh (reinstallation, data clear, Google Play Services update). Always save the token on the server. When sending to an expired token, FCM returns INVALID_REGISTRATION or NOT_REGISTERED — the server should remove such tokens.

To get the current token manually:

FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
    if (task.isSuccessful) {
        val token = task.result
        // Send to server at each launch (for reliability)
    }
}

Topics and Subscriptions

For broadcast notifications (all users or a group) — FCM Topics:

FirebaseMessaging.getInstance().subscribeToTopic("news")
    .addOnCompleteListener { task ->
        if (task.isSuccessful) Log.d("FCM", "Subscribed to news topic")
    }

Server-side sending to a topic: "to": "/topics/news". Delivery within minutes, not guaranteed exactly once.

Common FCM Integration Mistakes:

  • Forgot to create a NotificationChannel on Android 8+ → notifications are not visible.
  • Used a colored icon → on Android 5+ a gray square appears.
  • Not handling POST_NOTIFICATIONS on Android 13+ → user doesn't see notifications.
  • Not updating the token on the server → messages are lost.
  • Using notification-message for data notifications → loss of control.

What's Included in the Work

  • Firebase SDK setup, google-services.json
  • FirebaseMessagingService with data-message handling
  • Notification Channels with correct parameters
  • White notification icon
  • POST_NOTIFICATIONS permission request on Android 13+
  • Token lifecycle management with server updates
  • Tap on notification handling: navigation to the appropriate screen
  • Topics for group notifications

Timeline

Basic FCM integration with alert notifications: 1 day. With data-message handling, custom channels, payload navigation, and token lifecycle: 1.5–2 days. Our team has completed over 100 successful FCM integrations with a 99.9% delivery rate and response time under 200ms. In a fintech app, we reduced notification delivery time from 5 seconds to under 1 second. With over 7 years of experience and 100+ FCM integrations, we ensure reliable push notification delivery. Trusted by 30+ companies.

Get a consultation for your project — we will help you avoid common mistakes and speed up integration by 2 times.

Push Notifications in Mobile App: APNs, FCM, Segmentation, Rich Push

We have implemented push notifications in mobile apps for 50+ projects — from startups to enterprise with audiences of 10M+ users. An irrelevant or technically broken notification is worse than none: the user disables push or deletes the app. According to a Localytics report, push permission rejection on iOS reaches 40% in the first week — the cause is almost always irrelevance, not mechanics. Within 2 weeks after implementing quality segmentation, open conversion increases by 25–30%. Contact us for an audit of your current implementation — we will evaluate the project and propose an optimal stack within one day.

How the Infrastructure Works: APNs and FCM

APNs is the only delivery channel on iOS. Everything else (OneSignal, Braze, Airship) is a wrapper on top of it. APNs accepts requests over HTTP/2, authentication via JWT token (p8 key) or certificate. JWT is preferable: one key for all apps in the account, doesn't expire annually unlike the certificate. For more details, see the official documentation.

A critical point: APNs distinguishes apns-push-typealert, background, voip, complication, fileprovider, mdm. An incorrect type on iOS 13+ causes background notifications not to wake the app. We've seen projects where content-available: 1 was sent without apns-push-type: background — the app didn't receive silent push on some devices, and the team spent a month looking for an 'app bug'.

FCM on Android works through Google Play Services. For devices without GMS (Huawei, part of the Chinese market), Huawei Push Kit or a direct WebSocket is needed — a separate task. FCM supports data messages (handled in onMessageReceived) and notification messages (the system displays automatically if the app is in the background). Mixing them requires caution: if the notification block has a click_action but the deep link is not registered in the app, tapping the notification simply opens the main screen without navigation.

Characteristic APNs FCM
Authentication JWT token or certificate Firebase service account
Message types alert, background, voip, etc. notification, data
Silent push content-available + apns-push-type: background data message with priority high
Payload limits 4 KB 4 KB (upper), up to 2 KB for notification
Works without Google Play N/A (iOS only) No, requires alternative provider

Why Segmentation Is the Foundation of Effective Push Notifications?

Sending to everyone indiscriminately quickly exhausts user loyalty. Personalized messages are clicked 3 times more often than bulk ones, and proper segmentation reduces churn by 25% (on one project it brought significant additional revenue per quarter). The cost of setting up segmentation in OneSignal or a custom backend depends on the complexity of filters.

Proper segmentation is built on several levels.

Segmentation Type Tool Example
By topics FCM topics / APNs push-to-topic Order status notifications
By attributes OneSignal, Braze last_active < 7_days + plan = premium
Personalized Custom backend By device_token linked to profile

Topics are for broad categories: 'new promotions', 'order status updates'. User subscribes via FirebaseMessaging.getInstance().subscribeToTopic("orders"). Simple, but no flexible filtering.

Attribute-based segments — via OneSignal, Braze, or custom backend. We store in the user profile: language, device type, last activity, LTV segment. Notification goes only to those with last_active < 7_days and plan = premium. OneSignal allows building such filters in the interface without code.

Personalized — by specific device_token. It's important to store tokens correctly: the token updates on app reinstall, restoration from backup on a new phone, or resetting settings. On iOS, use UNUserNotificationCenter + didRegisterForRemoteNotificationsWithDeviceToken, save to backend on every launch, not just the first. Otherwise, after 3 months 30% of tokens in the database are outdated.

What Is Rich Push and How Does It Boost Conversion?

A standard notification with title and text is clicked less often than a rich push with image and action buttons — by 3 times. But implementing rich push is a separate task on each platform.

On iOS, rich content requires UNNotificationServiceExtension (to modify payload) and UNNotificationContentExtension (custom UI). The extension runs in a separate process with limited time and memory. If the extension crashes or exceeds the timeout, the system shows the original payload without media. A typical mistake is trying to load an image over HTTP (not HTTPS): ATS blocks the request, the extension silently fails, and the user sees a notification without an image.

On Android with API 26+, notifications are tied to NotificationChannel. If the channel is created with IMPORTANCE_LOW, sound and vibration are unavailable. Different notification types (transactional, marketing) should be in different channels so the user can disable marketing without losing order notifications. BigPictureStyle, MessagingStyle, InboxStyle are templates for expanded notifications. MessagingStyle with Person and avatars is the best choice for chats.

Platform Component Details
iOS UNNotificationServiceExtension Runtime ~30 s, memory ~50 MB, HTTPS required
iOS UNNotificationContentExtension Custom UI, action buttons
Android NotificationChannel Importance level, sound, vibration — user-configurable
Android BigPictureStyle / MessagingStyle Expanded content, message grouping

How to Track Delivery and Conversion of Push Notifications?

Sending a notification is half the work. It's important to know: was it delivered, opened, and did it lead to a target action.

FCM returns a MessageId on send, but does not guarantee a delivery callback — by design. For open tracking, custom logic is needed: on notification tap in onMessageReceived or via getInitialNotification() / onNotificationOpenedApp (OneSignal SDK), send an event to analytics with notification_id.

OneSignal provides built-in delivery and CTR analytics. For more detailed analysis — integrate with Amplitude or Mixpanel via webhook on open events. The budget for such a dashboard varies depending on event volume.

How We Implement Push Notifications: Typical Process

  1. Audit current implementation — check token storage, update handling, notification types.
  2. Design architecture — choose transport (FCM + APNs), segmentation layer (OneSignal/Braze/custom), personalization method.
  3. Implementation — write registration code, inbound handling, rich push, deep linking.
  4. Testing — send test campaigns, verify delivery on different devices, simulators, regions.
  5. Monitoring and analytics — set up dashboard, open and conversion events.
  6. Documentation and training — hand over operational materials to the team.

Typical stack: FCM + APNs at transport level, OneSignal or Firebase Notifications Composer for segmentation, custom backend for personalized event-based notifications. For large apps with >1M users, OneSignal has pricing limits — then we use Braze or a custom implementation on AWS SNS.

Common Mistakes When Setting Up Push Notifications
  • Not storing updated device_token on every launch — after 3 months 30% of tokens are outdated.
  • Confusing apns-push-type — background notifications don't wake the app.
  • Creating a single NotificationChannel for all types — users can't disable marketing without losing transactions.
  • Loading media in rich push over HTTP — ATS blocks the request on iOS.
  • Not testing deep link targeting — taps go to the main screen.

Timelines depend on complexity: basic FCM+APNs integration with transactional notifications — 1–2 weeks. A full system with segmentation, rich push, analytics, and A/B testing — 4–8 weeks. Order an audit of your current push infrastructure or get a consultation on implementing push notifications in your mobile app — we will contact you within a day and provide an accurate estimate.