Skip to main content

🔔 Android Push Notification Setup

For the full host-app setup sequence, see Android setup in the primary integration guide. This page retains the detailed Firebase and push walkthrough.

Pitel VoIP Flow​

When a user makes a call from the Pitel Connect app, the Pitel 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​

Pitel incoming-call data messages are delivered through FCM. The tested Flutter example handles Pitel messages in a native FirebaseMessagingService; normal background/OS-terminated delivery depends on device and OS behavior and should be verified on a physical device. Delivery after a user force-stop is not guaranteed.

WARNING
  • Android 13+ (API 33+): Requires runtime POST_NOTIFICATIONS permission to display notifications.
  • Android 14+ (API 34+): The SDK does not bundle USE_FULL_SCREEN_INTENT in its library manifest to comply with Google Play policies. If your calling app requires full-screen lockscreen incoming calls, declare USE_FULL_SCREEN_INTENT in android/app/src/main/AndroidManifest.xml. If not declared or granted, the SDK falls back to heads-up notifications. See the Android Full-Screen Intent Guide.
  1. Go to the Firebase Console.
  2. Create or select your Firebase project.
  3. Register your Android app applicationId (matching PitelSettings.appId). Android namespace is a separate Gradle setting and may have a different value.
  4. Download the google-services.json file and place it in your project under android/app/google-services.json.

Android Gradle Configuration​

The example uses AGP 8.11.1, Kotlin 2.2.20, Java/JVM target 17, minSdk 24 and Google Services 4.4.2. Merge the Kotlin DSL setup below; use the Groovy alternative only for Groovy projects.

The Android applicationId identifies the installed app and must match Firebase, the Pitel Portal and PitelSettings.appId. The Gradle namespace and Kotlin package may be different. Set the package at the top of CustomMessagingService.kt to the host app's Kotlin source package, then use that fully-qualified class (or a matching relative name) in the manifest. A .CustomMessagingService entry is only correct when it resolves to that class in the manifest package/namespace. The checked-in example uses com.example.pitel_voip_example for its Kotlin package and com.mobile.tech.app as its application ID.

Kotlin DSL (reference example)​

Add the Google Services plugin using the host project's existing plugin DSL/version catalog. The example uses Google Services 4.4.2. Typical Kotlin DSL placement is:

android/settings.gradle.kts (or the app's existing plugin management convention):

plugins {
id("com.google.gms.google-services") version "4.4.2" apply false
}

android/app/build.gradle.kts:

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
id("dev.flutter.flutter-gradle-plugin")
}

android {
defaultConfig {
minSdk = 24
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {
implementation("com.google.firebase:firebase-messaging:24.0.0")
}

Merge these settings into the existing app configuration; don't duplicate plugin blocks or downgrade a working toolchain. Add your own google-services.json for the same Firebase Android app ID as the host applicationId. After flutter run or an Android Gradle sync, confirm the Google Services task processes that application ID. The AAR contributes SDK manifest permissions/components and consumer R8 rules. Host-app runtime permission prompts remain the app's responsibility through the SDK permission API. No SDK keep-rule copy is normally needed.

Groovy alternative​

For an existing Groovy project, use the following instead of the Kotlin DSL blocks.

  1. In android/app/build.gradle, verify the minimum SDK version is 24 or higher:
    android {
    defaultConfig {
    minSdkVersion 24 // Android 7.0+
    }
    }
  2. Apply the Google Services Gradle plugin:
    • In root android/build.gradle:
      buildscript {
      dependencies {
      classpath 'com.google.gms:google-services:4.4.2'
      }
      }
    • In android/app/build.gradle:
      apply plugin: 'com.google.gms.google-services'
      Use these Groovy snippets instead of the Kotlin DSL blocks above; do not apply both setups.
Firebase Project Configuration​
  • Go to Project Settings → Cloud Messaging and manage API access in the Google Cloud Console. fcm1
  • Search for "Cloud Messaging" in the Google API Library and click Enable. fcm2 fcm3 fcm4
Service Account Key Generation​
  • In Project Settings → Service Accounts, click Generate new private key. fcm1 fcm7
  • This downloads a credentials .json file containing a private key. Use it for the Portal/backend credential field, not as google-services.json. Keep it private and never put it in the mobile app or source control. fcm8

Note


🔀 Co-existing with Custom FCM Services (Multiplexing Push)​

If your app already implements custom Firebase Cloud Messaging (FirebaseMessagingService) or uses other push libraries, Android's single-service limitation can cause notification delivery conflicts. Follow this standard multiplexing pattern used in the example app:

1. Create a Multiplexing Service in Native Android​

Create CustomMessagingService.kt in the directory matching its Kotlin package under android/app/src/main/kotlin/ (for example, com/example/yourapp/CustomMessagingService.kt):

package com.yourcompany.app

import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.pitel.voip.sdk.core.PitelClient

class CustomMessagingService : FirebaseMessagingService() {

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
val data = message.data
Log.d(TAG, "onMessageReceived: from=${message.from}, data=$data")

// 1. Check if the push payload belongs to Pitel VoIP
if (data.isNotEmpty() && PitelClient.isPitelPushNotification(data)) {
Log.d(TAG, "Pitel VoIP push detected, delegating to SDK")
PitelClient.initialize(applicationContext)
PitelClient.handleFCMMessage(applicationContext, data)
} else {
// 2. Pass non-Pitel notifications to your app's custom handler
Log.d(TAG, "Non-Pitel message, partner handles it")
// handleYourAppPush(message)
}
}

override fun onNewToken(token: String) {
super.onNewToken(token)
Log.d(TAG, "FCM token refreshed: $token")
PitelClient.initialize(applicationContext)
PitelClient.saveFcmToken(token)

// Forward new token to your own backend if needed
}

companion object {
private const val TAG = "CustomFCMService"
}
}

2. Configure AndroidManifest.xml​

In android/app/src/main/AndroidManifest.xml:

  1. Register your CustomMessagingService.
  2. Explicitly remove the default Pitel SDK service and FlutterFire messaging service using tools:node="remove" to ensure only your custom service receives the FCM intent.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<!-- Your custom multiplexing FCM service -->
<service
android:name=".CustomMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<!-- Remove SDK's default FCM service to avoid conflict -->
<service
android:name="com.pitel.voip.sdk.service.PitelFirebaseMessagingService"
tools:node="remove" />

<!-- Remove FlutterFire's FCM service if using CustomMessagingService -->
<service
android:name="io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService"
tools:node="remove" />
</application>
</manifest>

The service's Kotlin package/class and android:name must resolve to the same class. If the host's manifest package or Gradle namespace makes the relative .CustomMessagingService ambiguous, use its fully qualified name, such as com.example.yourapp.CustomMessagingService. Verify the merged manifest contains exactly one service with the MESSAGING_EVENT action. Removing FlutterFire's service means this custom native service does not forward ordinary messages to Dart; route those messages to the host's own handler if required.


📱 FlutterFire callbacks (optional)​

The example's custom Android service handles Pitel call pushes natively and removes FlutterFire's competing default service. It does not forward non-Pitel pushes to Dart. Add FlutterFire callbacks only for messages that your host app's configured routing actually delivers to FlutterFire; the callbacks are not the default Pitel call route. See Incoming calls and example/lib/main.dart for optional FlutterFire callback usage. iOS incoming VoIP calls continue through PushKit/APNs.

Token refresh and registration​

The service saves the initial/refreshed FCM token using PitelClient.saveFcmToken. On Android, saving a changed token does not itself send a new SIP REGISTER, so the backend may continue to have the previous token until the next registration. The Dart setFCMToken() call has the same limitation and its Future completion is not server acknowledgement.

When the host observes a changed token, retain the user's current PitelSettings in the host's own session state. After any active/incoming call has ended and the registration listener is no longer connecting, call login(currentSettings) to send a new registration containing the saved token, then wait for PitelRegistrationState.registered. Do not log out first, call autoLogin() as a token-refresh command, or start overlapping registration attempts. If the app cannot safely re-register at that time, retain a pending-refresh flag and perform the update at the next safe app-controlled point. Verify delivery with a new incoming call and backend diagnostics; token storage alone does not prove the server received it.

Check microphone and notification permissions while the app is foregrounded at startup and before outgoing calls. If an incoming event arrives while the app is foregrounded and permission is missing, explain the need and request permission then. Complete permission prompts before testing calls while backgrounded or locked; a background push handler cannot present a normal foreground permission flow.


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

Save this script as test_android_fcm.sh and run it from the default macOS zsh terminal with bash test_android_fcm.sh (the script uses Bash read -p). Enter the Firebase project_id, a short-lived OAuth access_token, and the target fcm_token at the prompts; none is hard-coded in the file. The access token is sensitive and should not be shared.

# Save the following contents as test_android_fcm.sh, then run: bash test_android_fcm.sh
set -euo pipefail
read -r -p "Firebase project ID: " FCM_PROJECT_ID
read -r -s -p "OAuth2 access token: " FCM_ACCESS_TOKEN; printf '\n'
read -r -s -p "Android device FCM token: " FCM_TOKEN; printf '\n'

curl --fail-with-body --location \
"https://fcm.googleapis.com/v1/projects/${FCM_PROJECT_ID}/messages:send" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${FCM_ACCESS_TOKEN}" \
--data-binary @- <<JSON
{
"message": {
"token": "${FCM_TOKEN}",
"android": { "priority": "HIGH" },
"data": {
"uuid": "77712f3-9b56-4e26-96ea-382ea1206477",
"nameCaller": "Pitel Voip",
"phoneNumber": "101",
"appName": "Pitel Connect",
"callType": "CALL"
}
}
}
JSON

A successful HTTP response means FCM accepted the request. It does not prove that a device received the message, that the native service dispatched it, that SIP is registered, or that a call connects. Verify each stage separately on a physical Android device using a test project/account; do not use production credentials in a shared terminal session. The command intentionally has no notification block or APNs configuration because it tests Android native delivery only.