Skip to main content

What this guide covers

  • Adding the cometchat_push_notifications plugin and initializing it.
  • Platform wiring: Gradle/Firebase on Android, Podfile/capabilities/AppDelegate on iOS.
  • Requesting permission and registering tokens (FCM on Android, APNs + VoIP on iOS) after login.
  • Receiving pushes and letting the SDK render chat notifications and full-screen calls.
  • Handling notification taps, incoming-call navigation, badge counts, and Android OEM permissions.
  • Testing and troubleshooting.
The cometchat_push_notifications plugin replaces the previous approach of copying the UI Kit sample’s lib/notifications stack and hand-wiring PNRegistry / CometChatPushRegistry, flutter_callkit_incoming, and native MainActivity / AppDelegate bridges. Token registration, foreground presentation, notification taps, badge management, and the full incoming-call experience (the Android lock-screen call activity and iOS CallKit) are handled inside the plugin.

How it works

  • Android (FCM): Firebase issues the registration token and delivers the CometChat payload as a data message. Your firebase_messaging handler forwards message.data to handlePushNotification, and the plugin shows the notification or full-screen call.
  • iOS (APNs + PushKit): Apple issues the APNs device token (chat alerts) and the VoIP token (calls). APNs alerts are shown by the system; VoIP pushes are presented through CallKit by the plugin.
  • CometChat’s role: The providers you add in the dashboard bind your registered tokens to the logged-in user so CometChat can route pushes on your behalf.
  • The plugin’s role: cometchat_push_notifications retrieves the tokens, registers them with CometChat, parses payloads, and drives the call UI. It builds on cometchat_sdk, which pub resolves for you.

Prerequisites

  • The providers, Firebase project, and Apple/APNs credentials from Getting Started (this guide assumes those are done).
  • Flutter 3.3.0+ / Dart 3.10.8+.
  • Android: Kotlin 2.0+, minSdkVersion 24, compileSdkVersion 36.
  • iOS: iOS 13.0+ (set the Podfile platform to 14.0 for VoIP/CallKit).
  • A physical device — background delivery, full-screen calls, and VoIP pushes are unreliable on emulators/simulators.
Complete the Getting Started guide first — enable Push Notifications, add your providers (FCM for Android, APNs + APNs VoIP for iOS), and finish the Firebase/Apple setup. This guide covers only the Flutter app wiring.

1. Store your credentials

Keep the values from Getting Started somewhere your app can read them. Only the fields for the platforms you ship are needed:

2. Add the plugin and configure the platform

Add the plugin to pubspec.yaml. On Android also add Firebase Messaging (used to receive the FCM data messages):
cometchat_sdk is pulled in transitively. Run flutter pub get.
With google-services.json already in android/app/ (from Getting Started):
  1. Apply the Google Services plugin and ensure Kotlin is 2.0+ in android/settings.gradle.kts:
  1. Apply the plugins in android/app/build.gradle.kts:
  1. Set applicationId to your package name and keep minSdk = 24 or higher. Run flutterfire configure if you still need firebase_options.dart.
You do not need to add notification, call, full-screen-intent, or lock-screen permissions to your AndroidManifest.xml. The plugin declares everything it needs (including the lock-screen IncomingCallActivity and the Decline broadcast receiver), and Gradle merges them into your app automatically.

3. Initialize the SDK

Initialize the plugin before runApp. On Android you also initialize Firebase and forward FCM messages to the plugin (including a background isolate handler).
The CometChatNotificationConfig also accepts: Once the navigator is ready on your first screen after login, replay any cold-start call launch and route subsequent call taps:
Pass the same navigatorKey to your MaterialApp.

Android: lock-screen call entrypoint

When a call arrives while the device is locked, the plugin launches a dedicated full-screen activity that runs a separate Dart entrypoint named incomingCallMain. Define it in main.dart. It talks to the plugin’s native activity over the cometchat_locked_call method channel:
Adapt the accept path to launch your in-call screen. The channel methods (getCallDetails, cancelNotification, finish, and the incoming reload) are the contract the plugin’s IncomingCallActivity exposes.

4. Request permission and register tokens

Request permission early, and register tokens after your CometChat user logs in (registration binds the token to the session):
Token refreshes are handled for you — the plugin listens for onTokenRefresh and automatically re-registers the new token with CometChat. Subscribe to CometChatPushNotifications.onTokenRefresh if you want to log it.

5. Notification taps and call events

Subscribe to the streams to navigate and coordinate call state (same on both platforms):
Useful call methods: setCallConnected(sessionId) (after media is established — critical for connecting calls from a terminated state), endCall(sessionId), endAllCalls() (on logout), and getActiveCallIds().
Cold-start VoIP handling (iOS): when the app is killed and a VoIP push arrives, the plugin presents CallKit natively via PushKit before the Flutter engine is ready. When the user answers, handleIncomingCallLaunch routes to your call screen and the onCallEvent / onCallAccepted handlers fire — set up your CometChat call session there and call setCallConnected.

6. Android: OEM permissions for lock-screen calls

To reliably show a full-screen call over the lock screen — especially on Android 14+ and OEM skins like MIUI/Redmi/POCO — check and request the relevant permissions:
On iOS and web these checks return “granted” and the open-settings calls are no-ops.

7. Badge count

CometChat’s Enhanced Push Notification payload includes an unreadMessageCount field (the total unread across all conversations). Enable it once on the dashboard:
  1. Go to CometChat Dashboard → Notification Engine → Settings → Preferences → Push Notification Preferences.
  2. Enable the Unread Badge Count toggle.
Set the badge from the payload (for example inside a foreground handler) using the plugin’s badge helper — no extra dependency needed:
Clear the badge and dismiss stale notifications when the app opens and every resume:
Add a WidgetsBindingObserver to your root widget and clear in initState and on AppLifecycleState.resumed.

8. Testing checklist

  1. Run on a physical device. Grant notification, microphone, and camera permissions when prompted (Android 13+ requires POST_NOTIFICATIONS).
  2. Send a message from another user:
    • Foreground: no banner unless showInAppNotifications: true (and you’re not already in that chat).
    • Background: a notification appears; tapping opens the right conversation via onNotificationTap.
  3. Force-quit the app, send another message, tap the notification, and confirm it navigates to the conversation.
  4. Trigger an incoming CometChat call and confirm:
    • The full-screen call UI (Android) / CallKit (iOS) shows the caller with Accept/Decline, even on the lock screen.
    • Accepting starts the call session (via onCallAccepted) and dismisses the notification when the call ends.
    • Declining rejects the call server-side (via your onCallDeclined).
  5. Toggle Wi-Fi/cellular and reinstall to confirm token registration survives refreshes.

9. Troubleshooting

Resources

cometchat_push_notifications

The drop-in push & VoIP plugin on pub.dev.

SDK source

Source, changelog, and example app.