Overview
When a user leaves your call screen, the operating system may terminate it to free resources. The SDK providesCometChatOngoingCallService — a utility that:
- Keeps the call session active in the background
- Shows an ongoing notification in the status bar (Android)
- Allows users to return to the call with a single tap
- Provides a hangup action directly from the notification
When to Use
Background Handling is different from Push Ringing. They cover different phases of a call on Android:
cometchat_voip stops its service once the session is joined, so a joined call needs this page whether it was rung through push or not. It applies to every call: ringing calls, direct calls, group calls and meetings.Implementation
Step 1: Declare the service and permissions (Android)
Add the ongoing call service and the notification permission toandroid/app/src/main/AndroidManifest.xml:
FOREGROUND_SERVICE, FOREGROUND_SERVICE_MICROPHONE and FOREGROUND_SERVICE_CAMERA). On Android 13 and later, request POST_NOTIFICATIONS at runtime as well (cometchat_voip already declares and requests it if your app uses it).
Optional: keep the notification when the microphone is denied
If a user joins a call without granting the microphone, the call continues listen-only. To keep the ongoing notification and the background protection in that case, add themediaPlayback type and its permission:
Google Play asks you to justify each foreground service type your app declares. Declare
mediaPlayback only if you can justify it for your app.Step 2: Start the service on join, stop it on leave
Start the ongoing call service when the user joins the call session, and stop it when the call ends. PassisVideo: false for an audio call, so the service doesn’t use the camera.
abort().
Flutter listeners are not lifecycle-aware. You must manually remove listeners in
dispose() and call CometChatOngoingCallService.abort() to clean up.API Reference
CometChatOngoingCallService
On iOS, ongoing call state is managed by CallKit automatically.
CometChatOngoingCallService.launch() and abort() are safe to call on iOS — they simply do nothing.Related Documentation
- Picture-in-Picture - Keep call visible while using other apps
- Push Ringing - Ring calls when the app is in the background or killed, until the answered call joins
- Events - Listen for session events