Skip to main content
FieldValue
PlatformAndroid (FCM)
Key ClassesCometChatNotifications, VoipNotificationHandler, PendingCallManager
Key MethodsregisterPushToken(), unregisterPushToken(), messaging().getToken()
Push PlatformCometChatNotifications.PushPlatforms.FCM_REACT_NATIVE_ANDROID
PrerequisitesCometChat SDK initialized, user logged in, FCM configured, google-services.json in android/app

React Native UI Kit Sample App

Reference implementation of React Native UI Kit, FCM and Push Notification Setup.

What this guide covers

  • CometChat Dashboard setup (enable push, add FCM providers).
  • Platform credentials (Firebase).
  • Copying the sample notification stack and aligning IDs/provider IDs.
  • Native glue for Android (manifest permissions).
  • VoIP call alerts with FCM data-only pushes + CallKeep native dialer.
  • Token registration, navigation from pushes, testing, and troubleshooting.

What you need first

  • CometChat app credentials (App ID, Region, Auth Key) and Push Notifications enabled with an FCM provider (React Native Android).
  • Firebase project with an Android app (google-services.json in android/app) and Cloud Messaging enabled.
  • React Native 0.81+, Node 18+, physical Android devices for reliable push/call testing.

How FCM + CometChat work together

  • FCM (Android) is the transport: Firebase issues the Android FCM token and delivers payloads to devices.
  • CometChat provider holds your credentials: The FCM provider you add (for React Native Android) stores your Firebase service account JSON.
  • Registration flow: Request permission → Android returns the FCM token → after CometChat.login, register with CometChatNotifications.registerPushToken(token, platform, providerId) using FCM_REACT_NATIVE_ANDROID → CometChat sends pushes to FCM on your behalf → the app handles taps/foreground events via Notifee.

1. Enable push and add providers (CometChat Dashboard)

  1. Go to Notifications → Settings and enable Push Notifications.
Enable Push Notifications
  1. Add an FCM provider for React Native Android; upload the Firebase service account JSON and copy the Provider ID.
Upload FCM service account JSON

2. Prepare platform credentials

2.1 Firebase Console

  1. Register your Android package name (same as applicationId in android/app/build.gradle) and download google-services.json into android/app.
  2. Enable Cloud Messaging.
Firebase - Push Notifications

3. Local configuration

  • Update src/utils/AppConstants.tsx with appId, authKey, region, and fcmProviderId.
  • Keep app.json name consistent with your bundle ID / applicationId.

3.1 Dependencies snapshot (from Sample App)

Install these dependencies in your React Native app:
Match these or newer compatible versions in your app.

4. Android App Setup

4.1 Configure Firebase with Android credentials

To allow Firebase on Android to use the credentials, the google-services plugin must be enabled on the project. This requires modification to two files in the Android directory. First, add the google-services plugin as a dependency inside of your /android/build.gradle file:
Lastly, execute the plugin by adding the following to your /android/app/build.gradle file:

4.2 Configure required permissions in AndroidManifest.xml as shown.

and ask for runtime permissions where needed (e.g. POST_NOTIFICATIONS on Android 13+).

4.3 Register FCM token with CometChat

Inside your main app file where you initialize CometChat, add the below code snippet after the user has logged in successfully. Initilize and register the FCM token for Android as shown:

4.4 Unregister FCM token on logout

Typically, push token unregistration should occur prior to user logout, using the CometChat.logout() method. For token unregistration, use the CometChatNotifications.unregisterPushToken() method provided by the SDKs.

5. VoIP call notifications

These steps are Android-only—copy/paste and fill your IDs.

5.1 Add CallKeep services to android/app/src/main/AndroidManifest.xml

Inside the <application> tag add:

5.2 Background handler for call pushes (index.js)

Data-only FCM calls show the native dialer even when the app is killed.

5.3 Drop in VoipNotificationHandler.ts

Handles CallKeep setup, shows the incoming call UI, accepts/rejects via CometChat, and defers acceptance if login/navigation isn’t ready.

5.4 Add PendingCallManager.ts

Stores an answered call during cold-start so you can accept it once login/navigation is ready.

5.5 Wire App.tsx to init VoIP + consume pending accepts

Add this after CometChat init/login:

5.6 Call push payload (FCM data)

Send a data-only FCM message like:

5.7 Local notification helper (LocalNotificationHandler.ts)

Ensure @notifee/react-native is installed (listed in Dependencies above). Add this helper next to your index.js to show local alerts for non-call pushes:
  • For a proper notification icon, create a dedicated ic_notification.xml (vector) or PNG in android/app/src/main/res/drawable/; Android expects a white glyph with transparency for best results.

6. Handling notification taps and navigation

To handle notification taps and navigate to the appropriate chat screen, you need to set up handlers for both foreground and background notifications.

7. Badge Count Implementation

CometChat’s Enhanced Push Notification payload includes an unreadMessageCount field that represents the total number of unread messages across all conversations for the logged-in user. You can use this value to update the app icon badge, providing users with a visual indicator of unread messages.

7.1 Enable Unread Badge Count on the CometChat Dashboard

1

Navigate to Push Notification Preferences

Go to CometChat Dashboard → Notifications Engine → Settings → Preferences → Push Notification Preferences.
2

Enable the Toggle

Scroll down and enable the Unread Badge Count toggle.
Once enabled, CometChat automatically includes the unreadMessageCount field in every push payload sent to your app.

7.2 Expected Payload Format

CometChat sends push notifications with the following structure:
The unreadMessageCount field is a string representing the total unread messages across all conversations for the logged-in user.

7.3 Handle Badge Count in Background Messages

Update your FCM background message handler in index.js to extract and set the badge count:

7.4 Handle Badge Count in Foreground Messages

In your App.tsx, set up a listener for foreground FCM messages:

7.5 Display Local Notification with Badge Count

Update your notification display function to include the badge count:

7.6 Clear Badge When App Becomes Active

Clear all notifications and reset the badge when the app returns to the foreground:

7.7 Clear Badge on Logout

When a user logs out, clear the badge so it doesn’t show a stale count on the login screen or for the next user:

7.8 Clear Badge on Fresh Install / No Logged-In User

Clear the badge during app initialization when no user is logged in. This handles cases where badge count may persist after app reinstall:

7.9 Clear Badge in Login Listener (Safety Net)

Register a login listener to clear the badge on logout as a backup mechanism:

7.10 Key Implementation Notes

ConsiderationDetails
Backend-driven badge countThe unreadMessageCount value comes directly from CometChat’s backend via the push payload, ensuring consistency across all devices.
Fixed notification IDUsing a fixed notification ID ('chat-notification') prevents certain devices from accumulating badge counts across multiple notifications. The badge always reflects the exact unreadMessageCount from the backend.
Clear on app activeAlways clear the badge when the app becomes active. New notifications will update the badge with the fresh unreadMessageCount from the backend.
Clear on logoutAlways clear the badge when a user logs out to prevent stale counts for the next user.
Clear on fresh installClear the badge during app initialization when no user is logged in to handle reinstall scenarios.
Login listener safety netUse CometChat’s login listener as a backup to ensure badge is cleared on logout.
Title enhancementOptionally display the unread count in the notification title (e.g., “John (5 unread)”) for devices that don’t support app icon badges.

8. Testing Checklist

  1. Install on a physical Android device, grant POST_NOTIFICATIONS permission, log in, and verify FCM token registration succeeds.
  2. Send a message from another user:
    • Foreground: Notifee banner appears unless that chat is already open.
    • Background/terminated: Tap opens the correct conversation; Notifee background handler runs.
  3. VoIP call: Send a callAction=initiated push; expect the native dialer to appear. Answer and verify the call connects; send callAction=ended to dismiss it.
  4. Rotate tokens (reinstall or revoke) and confirm onTokenRefresh re-registers the new token.

9. Troubleshooting

SymptomQuick Checks
No pushesConfirm google-services.json location, package IDs match Firebase, Push extension enabled with correct provider IDs, permissions granted.
Token registration failsEnsure registration runs after login, provider IDs are set, and registerDeviceForRemoteMessages() is called.

Next Steps

Push Notifications (iOS)

Set up APNs push notifications for iOS

Push Notification Content Customization

Strip HTML tags and customize notification content

Send Messages

Learn how to send different types of messages

Receive Messages

Handle incoming messages in real time