What this guide covers
- Adding the
push-notifications-androidSDK and initializing it. - Wiring your own Firebase Messaging service to forward payloads to the SDK.
- Requesting permission and registering the FCM token after login.
- Letting the SDK render chat notifications (grouped, inline reply) and full-screen VoIP calls.
- Handling notification taps and call events, and suppressing notifications for the open chat.
- Testing and troubleshooting.
The
push-notifications-android SDK replaces the previous approach of copying the UI Kit sample’s fcm/ and voip/ packages (FCMService, FCMMessageNotificationUtils, FCMMessageBroadcastReceiver, CometChatVoIP, CometChatVoIPConnectionService, and related helpers). Token registration, notification channels, stacking, avatars, inline reply, delivery receipts, the VoIP ConnectionService, the incoming-call screen, ring timeout, call-collision handling, and SDK auto-init on a killed-app wake are all handled inside the SDK. Your app keeps only a ~5-line Firebase Messaging service and three facade calls.How it works
- FCM’s role: Firebase issues the registration token and delivers the CometChat payload as a data message. The SDK does not depend on
firebase-messaging— your app owns Firebase and passes the payload as aMap<String, String>. - CometChat’s role: The FCM provider you add in the dashboard binds your registered token to the logged-in user so CometChat can route pushes on your behalf.
- The SDK’s role:
CometChatPushNotificationsparses the payload and decides chat vs call. Chat → builds/stacks notifications. Call → drives a full-screen incoming-call experience over an Android TelecomSELF_MANAGEDConnectionService(the same approach WhatsApp/Signal use — noREAD_PHONE_STATE/ANSWER_PHONE_CALLSand no phone-account toggle in Settings). - Killed-app wake: When FCM starts your process,
init()inApplication.onCreate()runs first and stores your credentials;handlePushNotification(...)then auto-initializes the Chat SDK before routing, so calls connect even from a terminated state.
Prerequisites
- The FCM provider, Firebase project, and
google-services.jsonfrom Getting Started (this guide assumes those are done). - The CometChat Chat SDK / UI Kit already integrated (you call
CometChatUIKit.init()/login()yourself). - minSdk 24+, compileSdk 36, Java 11, and a Gradle/AGP version matching your UI Kit project.
- A physical device — background delivery and full-screen calls are unreliable on emulators.
Complete the Getting Started guide first — enable Push Notifications, add your FCM provider, and configure Firebase (
google-services.json + service account JSON). This guide covers only the Android app wiring.1. Add the dependency
Add the CometChat Maven repository (the same one that serves the Chat and Calls SDKs) insettings.gradle.kts:
settings.gradle.kts
google-services plugin so google-services.json is picked up:
app/build.gradle.kts
You do not need to add notification, full-screen-intent, foreground-service,
WAKE_LOCK, or MANAGE_OWN_CALLS permissions, or declare the incoming-call activity / VoIP services in your AndroidManifest.xml. The SDK’s manifest declares everything it needs and Gradle merges it into your app automatically.2. Store your credentials
Keep the values from Getting Started where your app can read them:AppCredentials.kt
3. Initialize the SDK
Initialize inApplication.onCreate() so the SDK is ready before any push arrives (including killed-app wakes). Build the config with PNConfiguration.Builder(appId, region):
MyApplication.kt
<application android:name> at MyApplication in your manifest.
4. Forward FCM payloads to the SDK
Create your ownFirebaseMessagingService. Forward each data message to handlePushNotification(...) and each token to handleTokenRefresh(...):
AppFCMService.kt
AndroidManifest.xml
handlePushNotification also accepts optional title, body, icon, uid, and guid overrides — pass uid/guid if you want to control the notification grouping key. For the default experience, just pass data.5. Request permission and register the token
RequestPOST_NOTIFICATIONS (Android 13+) early using the SDK helper, and register the token after login so it binds to the session:
6. Notification taps and call events
Suppress notifications for the chat that is currently open, and set the tap listener so you can navigate when a chat notification is tapped:To fully replace the built-in call screen with your own, set
setOnIncomingCallHandler(...) (override the ringing screen) and/or setOnCallAnsweredHandler(...) (override the post-accept ongoing-call screen). The SDK still manages ringtone, ring timeout, and cleanup.7. Badge count
CometChat’s Enhanced Push Notification payload includes anunreadMessageCount field (a string, total unread across all conversations). Enable it once on the dashboard: CometChat Dashboard → Notification Engine → Settings → Preferences → Push Notification Preferences → Unread Badge Count.
Parse it from the payload and set the app-icon badge with a launcher badge library such as ShortcutBadger:
onResume of your main activity).
8. Testing checklist
- Install on a physical device and grant notification + mic permissions (Android 13+ needs
POST_NOTIFICATIONS). - Log in and confirm token registration succeeds (check the
registerTokensuccess callback / Logcat). - Send a message from another user:
- App open in a different chat: notification appears (grouped, with inline reply).
- App backgrounded/killed: notification appears; tapping opens the right conversation via
onNotificationTapped. - No notification for the chat currently open (via
setCurrentOpenChatId).
- Trigger an incoming CometChat call and confirm the full-screen call UI shows the caller with Accept/Decline, even on the lock screen; Accept joins the call, Decline rejects it.
- Toggle Wi-Fi/cellular and reinstall to confirm token registration survives refreshes (
onNewToken→handleTokenRefresh).
9. Troubleshooting
Resources
push-notifications-android
The drop-in push & VoIP SDK on the CometChat Maven repo.
SDK source
Source, changelog, and sample.