Skip to main content

🔔 Android Push Notification Setup

VoIP Flow​

When a user makes a call from the VoIP app, the VoIP Server pushes a notification to all logged-in extensions receiving the call.

VoIP call flow

Call UI Experience​

Android (Alert) - AudioAndroid (Lockscreen / Fullscreen) - Audio
Android AlertAndroid Lockscreen

Setup & Credentials​

We use FCM (Firebase Cloud Messaging) to handle push notifications that wake up the app when it is in the Background or Terminated.

Warning Requesting runtime notifications permission only works on devices running API level 33 (Android 13) or higher.

📌 Step 1: Firebase Project Configuration​

  1. Go to the Firebase Console.
  2. Create or select your Firebase project.
  3. Register your Android app package ID (e.g. com.yourcompany.app).
  4. Download the google-services.json file and place it in your React Native project under android/app/google-services.json.

📌 Step 2: Configure Android Build Files​

To enable Google Services inside your Android app:

  1. Add the Google Services classpath to your project-level android/build.gradle:

    buildscript {
    dependencies {
    // Add this line if not present
    classpath 'com.google.gms:google-services:4.3.15' // Or newer
    }
    }
  2. Apply the Google Services plugin and ensure FCM dependencies in your app-level android/app/build.gradle:

    // Add this at the top or bottom of the file
    apply plugin: 'com.google.gms.google-services'

    dependencies {
    // Required to resolve FirebaseMessagingService / RemoteMessage supertype during Kotlin compilation
    implementation("com.google.firebase:firebase-messaging:24.0.0")
    }

📌 Step 3: Autolinking & Permissions​

3.1 Permissions Reference​

The VoIP SDK automatically merges all required permissions via React Native Autolinking. For reference, or if your project requires explicit declarations in android/app/src/main/AndroidManifest.xml inside <manifest>:

<!-- Audio & Network -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<!-- Lockscreen & Wakeup -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.VIBRATE" />

<!-- Foreground Services (Android 14+) -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- Bluetooth Audio (Optional) -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

Incoming-call presentation: Incoming calls default to fullscreen mode with notification fallback. Apps that choose fullscreen must explicitly declare USE_FULL_SCREEN_INTENT and follow the Full-Screen Intent guide. Use incomingCallMode: 'notification' for apps that should not request FSI.

3.2 Manifest Configuration​

  • To prevent Google Play Store from filtering out devices without telephony hardware (such as Android tablets), add the following inside <manifest> in android/app/src/main/AndroidManifest.xml:
    <uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
  • Ensure the <manifest> tag defines the tools namespace:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
  • The background service (PitelCallService / PitelCallActiveService) and receiver (PitelCallActionReceiver) are declared and handled automatically.
  • The FCM receiver service PitelFirebaseMessagingService is registered to listen to incoming call events natively.
  • ProGuard / Release Builds: The SDK bundles its own consumer ProGuard keep rules automatically.

📌 Step 4: Firebase Service Account Key Generation​

VoIP Server requires this to route calls to FCM.

  1. In Firebase Console, go to Project Settings → Service Accounts.
  2. Click Generate new private key. fcm7
  3. This downloads a credentials .json file containing your private key. (Keep this file for configuring the portal). fcm8

Note

  • After completing the steps above, please configure the credentials on the SDK Portal.
  • Please check the Portal Setup Guide to complete your portal configuration.

📌 Co-existing with Custom Push Notification Services​

If your app already implements its own custom Firebase Messaging Service (or uses other push notification services alongside VoIP), you might face conflicts because Android only invokes one FirebaseMessagingService in the merged manifest.

To solve this, VoIP SDK exposes public utility helpers to safely delegate incoming call notifications.

  1. Create Custom Messaging Service: Create android/app/src/main/java/<package_path>/MyCustomMessagingService.kt (inheriting ReactNativeFirebaseMessagingService):
package <YOUR_APP_PACKAGE_NAME>

import com.google.firebase.messaging.RemoteMessage
import com.pitel.voip.sdk.core.PitelClient
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService

class MyCustomMessagingService : ReactNativeFirebaseMessagingService() {

override fun onMessageReceived(remoteMessage: RemoteMessage) {
val data = remoteMessage.data

// 1. Check if the FCM payload belongs to a VoIP call
if (PitelClient.isPitelPushNotification(data)) {
// Initialize and let VoIP SDK handle the incoming call natively
PitelClient.initialize(applicationContext)
PitelClient.handleFCMMessage(applicationContext, data)
} else {
// 2. Otherwise, forward standard push to React Native Firebase
super.onMessageReceived(remoteMessage)
}
}

override fun onNewToken(token: String) {
PitelClient.initialize(applicationContext)
PitelClient.saveFcmToken(token)
super.onNewToken(token)
}
}
  1. Register in android/app/src/main/AndroidManifest.xml inside <application>: You must declare MyCustomMessagingService and explicitly remove default conflicting services with tools:node="remove":
      <!-- Custom Firebase Messaging Service to multiplex notifications -->
<service
android:name=".MyCustomMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<!-- Remove standard services to prevent conflicts -->
<service
android:name="com.pitel.voip.sdk.service.PitelFirebaseMessagingService"
tools:node="remove" />
<service
android:name="io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService"
tools:node="remove" />

<!-- Override default notification channel conflict -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="pitel_incoming_call_channel_v3"
tools:replace="android:value" />

Option B: React Native JavaScript Delegation​

If you prefer handling and routing all background notifications inside JavaScript, check the payload and invoke the SDK bridge method:

import messaging from '@react-native-firebase/messaging';
import { PitelVoipClient } from 'react-native-pitel-voip-v2';

messaging().setBackgroundMessageHandler(async (remoteMessage) => {
const data = remoteMessage.data;

const callType = data?.callType ?? data?.call_type ?? data?.type;
if (data && typeof callType === 'string' && ['CALL', 'CANCEL_ALL', 'CANCEL_GROUP'].includes(callType)) {
// Forward incoming-call and cancellation payloads to the SDK.
await PitelVoipClient.instance.handlePushNotification(data);
} else {
// Process your app's normal push notification
handleAppNotification(remoteMessage);
}
});

Testing Push Notifications via cURL​

You can test push notifications using cURL or tools like Postman.

How to get an OAuth2 Access Token?​

  1. Go to the Google OAuth2 Playground.
  2. Under Step 1 (Select & authorize APIs), scroll or search for "Firebase Cloud Messaging API v1", select it and click Authorize APIs. step_1
  3. Grant permissions, then click Exchange authorization code for tokens under Step 2 to generate your Access Token. step_2

Use this cURL command to send a data-only, high-priority test message. Replace the YOUR_* placeholders before running it. Do not add a notification object: in the background, that routes the message to the system tray instead of the call service.

curl --location 'https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--data '{
"message": {
"data": {
"uuid": "77712f3-9b56-4e26-96ea-382ea1206477",
"nameCaller": "VoIP SDK",
"phoneNumber": "101",
"appName": "App Name",
"callType": "CALL"
},
"android": {
"priority": "high"
},
"token": "YOUR_FCM_TOKEN"
}
}'