Push Notification Quickstart with telnyx_common
Thetelnyx_common module provides a comprehensive SDK implementation, including push notification handling for your Android application. This guide will help you quickly integrate Telnyx’s push notification system using the ready-made components available in the telnyx_common module.
Overview
Thetelnyx_common module offers a complete solution for handling push notifications for incoming calls, including:
- Receiving and parsing Firebase Cloud Messaging (FCM) notifications
- Displaying appropriate notifications for incoming calls
- Handling user interactions with notifications (answer, reject, end call)
- Managing notification channels and importance levels
- Supporting both modern CallStyle notifications and legacy notifications for backward compatibility
telnyx_common module as a drop-in solution for your application.
Key Components
MyFirebaseMessagingService
MyFirebaseMessagingService is responsible for receiving and processing incoming Firebase Cloud Messaging (FCM) push notifications for calls.
Key Features:
- Parses incoming push notifications and extracts call metadata
- Handles different types of notifications (incoming calls, missed calls)
- Routes notifications to the appropriate handlers
- Supports both modern CallStyle notifications and legacy notifications
- Register the service in your AndroidManifest.xml:
CallNotificationService
CallNotificationService handles the creation and management of call notifications using Android’s modern CallStyle API.
Key Features:
- Creates and manages notification channels with appropriate importance levels
- Displays incoming call notifications with answer/reject actions
- Shows ongoing call notifications with end call action
- Supports full-screen incoming call UI
- Configures appropriate sounds, vibration patterns, and priority levels
MyFirebaseMessagingService when an incoming call is received. No additional setup is required if you’re using the telnyx_common module.
CallNotificationReceiver
CallNotificationReceiver is a BroadcastReceiver that handles user interactions with call notifications.
Key Features:
- Processes answer, reject, and end call actions from notifications
- Routes actions to the appropriate handlers in your application
- Cancels notifications when actions are taken
- New: Uses
BackgroundCallDeclineServicefor simplified call rejection without app launch
- Register the receiver in your AndroidManifest.xml:
BackgroundCallDeclineService
BackgroundCallDeclineService is a new service that handles call decline operations without launching the main application.
Key Features:
- Declines incoming calls in the background without app launch
- Connects to socket with
decline_pushparameter for simplified decline flow - Automatically disconnects after decline operation is complete
- Includes timeout handling to prevent service from running indefinitely
- Improves user experience by avoiding unnecessary app launches
- User taps decline on push notification
CallNotificationReceiverstartsBackgroundCallDeclineService- Service connects to socket using
connectWithDeclinePush() - Service sends login with
decline_push: trueparameter - Service automatically disconnects and stops after decline is processed
CallNotificationReceiver when using the telnyx_common module. No additional setup is required.
LegacyCallNotificationService
LegacyCallNotificationService is a legacy notification service maintained for backward compatibility.
Key Features:
- Provides fallback notification handling for devices that don’t support CallStyle
- Creates and manages notification channels
- Displays incoming call notifications with answer/reject actions
- Handles ringtone playback for incoming calls
- Register the service in your AndroidManifest.xml and specify your main activity:
Integration Steps
To integrate push notifications using thetelnyx_common module:
-
Set up Firebase Cloud Messaging (FCM) in your project:
- Follow the Firebase setup guide
- Add the necessary dependencies to your app’s build.gradle file
- Configure your Firebase project and download the google-services.json file
- Register the notification components in your AndroidManifest.xml:
- Handle push notification actions in your main activity:
- Configure the CallForegroundService for ongoing calls:
Sample App References
You can refer to our sample apps for complete implementations:Compose Sample App
The Compose sample app demonstrates how to integrate push notifications in a Jetpack Compose application:- AndroidManifest.xml - Shows how to register the notification components
- MainActivity.kt - Demonstrates handling push notification intents
XML Sample App
The XML sample app shows the integration in a traditional XML-based Android application:- AndroidManifest.xml - Shows how to register the notification components
- MainActivity.kt - Demonstrates handling push notification intents
Push Notification Decline - Migration Guide
New Simplified Approach (Recommended)
If you’re using thetelnyx_common module, the new BackgroundCallDeclineService is automatically used for call rejections. This provides:
- Improved User Experience: No app launch interruption when declining calls
- Better Performance: Reduced battery usage and faster response times
- Simplified Implementation: No need to handle complex invite/bye message flows
Legacy Approach (For Custom Implementations)
If you have a custom implementation that manually handles call decline, you may want to migrate to the new approach: Old Flow:Best Practices
-
Permissions: Ensure your app has the necessary permissions for notifications and foreground services:
-
Notification Channels: The
telnyx_commonmodule automatically creates appropriate notification channels, but you may want to customize them for your app’s branding. - Testing: Test push notifications on different Android versions to ensure compatibility with both modern CallStyle notifications and legacy notifications.
-
Background Processing: Use the
CallForegroundServiceto maintain calls when your app is in the background. - Error Handling: Implement proper error handling for push notification processing to ensure a smooth user experience.
-
Call Decline: Use the new
BackgroundCallDeclineServicefor optimal user experience when declining calls from push notifications.
Troubleshooting
- If notifications are not appearing, check that notification permissions are granted and channels are properly configured.
- For issues with Firebase Cloud Messaging, verify that your FCM setup is correct and that you have the latest version of the Firebase SDK.
- If call notifications are not working correctly, ensure that the
activity_class_namemetadata in your AndroidManifest.xml points to the correct activity. - For notification sound issues, check the audio settings on the device and verify that the notification channel is configured with the correct sound settings.
- Double-check the Telnyx portal to make sure push credentials are assigned properly.