Integrate VoIP call to your project (V2)
This document provides detailed instructions for integrating VoIP functionalities, including registering an account, making calls, and logging out using pitel-voip-sdk (V2).
π± Screenshots & Demoβ
1. Native Call Screen (PitelCallActivity) | 2. Lockscreen Fullscreen (FULLSCREEN) | 3. Heads-up Notification (NOTIFICATION) |
|---|---|---|
![]() | ![]() | ![]() |
| Integrated Compose in-call screen | Incoming call on lockscreen | Incoming call heads-up notification banner |
π Documentation Indexβ
| Guide | Description |
|---|---|
| π Step-by-Step Integration Guide | Standard 4-step lifecycle integration with PitelClient. |
| π¨ UI Customization Guide | Complete theme colors, dark mode, button icons, and custom text labels. |
| π€ Android Push Notifications | Firebase setup, service account, custom FirebaseMessagingService, and cURL test. |
| π‘οΈ Full-Screen Intent Guide | Android 14+ FSI compliance, lockscreen call presentation, and Google Play policy. |
| π Web Portal Setup Guide | Configure app identifiers and upload Firebase credentials to Pitel Portal. |
| π SIP Status Codes Reference | SIP disconnect codes, causes, and call end handling. |
| π οΈ Troubleshooting Guide | Solutions for registration errors, audio routing, permissions, and network issues. |
1. System Requirementsβ
- Android SDK 24+
targetSdkVersion >= 33- Firebase configured for Android (
google-services.jsonfile placed in your app'sapp/directory). - Google Services Gradle Plugin (
com.google.gms.google-services) applied to your app module.
2. Library Installationβ
Proguard/R8 keep rules are already bundled inside the SDK package (consumer-rules.pro). They will be automatically inherited by your application, so you do not need to manually add them to your proguard-rules.pro.
Add Dependenciesβ
You can integrate the SDK either as a local module (Option A) or import it as a remote Maven package from GitHub Packages (Option B).
Option A: Local Module Integration (Subproject)β
If you are developing/debugging using the SDK source code locally:
-
In your
settings.gradle.kts:include(":pitel-voip-sdk") -
In your
app/build.gradle.ktsdependencies:dependencies {
implementation(project(":pitel-voip-sdk"))
}
Option B: Remote Maven Integration (GitHub Packages)β
If you are integrating the compiled SDK artifact in a partner application:
-
Configure GitHub Packages credentials in your
settings.gradle.ktsor rootbuild.gradle.kts:dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/voip-sdk/android-pitel-voip-sdk-v2")
credentials {
username = YOUR_GITHUB_USERNAME
password = YOUR_GITHUB_PERSONAL_ACCESS_TOKEN
}
}
}
} -
Apply the Google Services plugin and add dependencies to your
app/build.gradle.kts:plugins {
alias(libs.plugins.android.application) // or id("com.android.application")
alias(libs.plugins.kotlin.android) // or id("kotlin-android")
id("com.google.gms.google-services") // Required to process google-services.json
}
dependencies {
implementation("com.pitel.voip:sdk:1.0.8") // Check GitHub Releases for the latest version
implementation("com.google.firebase:firebase-messaging-ktx:23.4.0")
}
Firebase Setup & Pitel Portal Configuration:
- Place your own Firebase project's
google-services.jsonfile inside your application'sapp/directory (app/google-services.json). - You must configure your Firebase Service Account credentials on the Pitel Web Portal matching your
applicationIdso that the Pitel PBX server can send push notifications to wake up devices for incoming calls. See Push Notifications Setup Guide for full instructions.
3. Configure AndroidManifest.xmlβ
The SDK AAR automatically bundles and merges core background telephony permissions (FOREGROUND_SERVICE, FOREGROUND_SERVICE_PHONE_CALL, WAKE_LOCK, POST_NOTIFICATIONS, VIBRATE, ACCESS_NETWORK_STATE).
In your application manifest (app/src/main/AndroidManifest.xml), you strictly only need to declare the app-level permissions:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- Required: Microphone recording permission for voice calls -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional: Required only for lockscreen full-screen incoming call UI on Android 14+ -->
<!-- Do NOT declare if your app does not qualify for Google Play Call/Alarm policy -->
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
</manifest>
Automatic Manifest Merging & Google Play FSI Policy:
- Core background telephony permissions are automatically merged by Gradle. You do not need to duplicate them.
- Google Play FSI Compliance: The SDK deliberately does not declare
USE_FULL_SCREEN_INTENTinternally so that apps not eligible for Google Play's full-screen calling exception won't be flagged. For complete details, see Android Full-Screen Intent Guide.
4. Step-by-Step Integration Guideβ
The SDK provides a standard, production-ready lifecycle designed for modern Android applications:
flowchart LR
A["Step 1: Init SDK<br/>(Application / Startup)"] --> B["Step 2: Register Account<br/>(User Login)"]
B --> C["Step 3: Calls & Events<br/>(In-App Calling)"]
C --> D["Step 4: Logout<br/>(User Signout)"]
Step 1: Initialize the SDK (App Startup)β
Call PitelClient.init(...) once when your app starts (in your Application class or main entry Activity):
import com.pitel.voip.sdk.core.PitelClient
import com.pitel.voip.sdk.ui.PitelCallUIConfig
// 1. Initialize SDK core, audio engine, and call overlay UI
PitelClient.init(
context = this,
autoLaunchCallScreen = true, // Automatically display in-call overlay on active calls
userAgent = "YOUR_APP_NAME", // Optional (default: "Pitel VoIP Android")
uiConfig = PitelCallUIConfig(), // Optional UI customizations (see Section 5)
incomingCallMode = PitelClient.IncomingCallMode.FULLSCREEN // Optional: FULLSCREEN (default) or NOTIFICATION
)
// 2. Request Notification and Microphone permissions
if (!PitelClient.hasRequiredPermissions(this)) {
PitelClient.requestPermissions(this, requestCode = 100)
}
// 3. Optional: Check Full-Screen Intent status on Android 14+
val fsiStatus = PitelClient.getFullScreenIntentStatus(this)
if (fsiStatus == PitelClient.FullScreenIntentStatus.NOT_GRANTED) {
PitelClient.openFullScreenIntentSettings(this)
}
Passing Firebase Token: Pass your FCM token to the SDK whenever obtained or refreshed:
PitelClient.saveFcmToken(fcmToken)If your application uses a custom
FirebaseMessagingService, see Push Notifications Setup Guide.
PitelClient.init(...) Parameters Referenceβ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
context | Context | Yes | β | Application or Activity context. |
fcmToken | String | Yes* | β | FCM device registration token (required to receive incoming calls; pass here or via saveFcmToken). |
mobileUsername | String? | No | "agentXX" | Mobile agent identifier for PBX push token management. If omitted, SDK automatically derives "agentXX" from the last 2 digits of extension (e.g. 101 $\rightarrow$ "agent01"). |
userAgent | String? | No | "Pitel VoIP Android" | Custom User-Agent header (automatically sanitized to max 30 alphanumeric characters). |
autoLaunchCallScreen | Boolean | No | true | When true, automatically reveals the native in-call screen overlay upon connected calls. |
uiConfig | PitelCallUIConfig | No | PitelCallUIConfig() | Visual styling configuration for colors, buttons, texts, and icons. |
incomingCallMode | IncomingCallMode | No | FULLSCREEN | Presentation mode: FULLSCREEN (lockscreen activity) or NOTIFICATION (heads-up banner). |
* Important Note on FCM Token (Required for Incoming Calls):
Firebase fetches registration tokens asynchronously (FirebaseMessaging.getInstance().token.addOnCompleteListener). If the FCM token is not yet ready when calling PitelClient.init(...):
- You can omit the
fcmTokenparameter in the initialinitcall. - HOWEVER, YOU MUST call
PitelClient.saveFcmToken(token)as soon as Firebase returns the token (and insideonNewToken), before callingPitelClient.registerAccount(...). Without an FCM token, the PBX server cannot deliver push notifications to wake up devices for incoming calls.
Incoming Call Presentation Modes (IncomingCallMode)β
The SDK provides two incoming call display strategies to match your app's Google Play policy requirements:
| Mode | Behavior | Requirements / Best For |
|---|---|---|
PitelClient.IncomingCallMode.FULLSCREEN(Default) | Wakes up the device screen and displays the full-screen call UI (PitelCallActivity) over the lockscreen. | Requires <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />. Recommended for core telephony/calling apps. |
PitelClient.IncomingCallMode.NOTIFICATION | Displays a high-priority heads-up notification banner with Answer & Decline action buttons. | Does not require FSI permission. Ideal for non-calling apps (e.g., e-commerce, banking) to ensure smooth Google Play policy compliance. |
You can configure this mode during PitelClient.init(...) or update it dynamically at runtime:
// Change presentation mode dynamically
PitelClient.setIncomingCallMode(PitelClient.IncomingCallMode.NOTIFICATION)
// Check current mode
val currentMode = PitelClient.getIncomingCallMode()
For full Android 14+ FSI compliance details, see Android Full-Screen Intent Guide.
Step 2: Register SIP Account (When User Logs In)β
When your user logs into the app and SIP credentials are provided by your backend:
PitelClient.registerAccount(
extension = "YOUR_EXTENSION", // e.g., "101"
password = "YOUR_PASSWORD", // e.g., "your_sip_password"
domain = "YOUR_DOMAIN", // e.g., "sip.domain.com"
proxy = "YOUR_PROXY", // e.g., "sip:proxy.domain.com:5061"
port = "YOUR_SIP_PORT", // Optional (default: "50061")
displayName = "YOUR_DISPLAY_NAME", // Optional (e.g., "Agent 101")
mobileUser = "YOUR_MOBILE_USER", // Optional (e.g., "agent01" for PBX push token management)
userAgent = "YOUR_USER_AGENT" // Optional (default: "Pitel VoIP Android")
)
PitelClient.registerAccount(...) Parameters Referenceβ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
extension | String | Yes | β | SIP extension/username (e.g., "101"). |
password | String | Yes | β | SIP account password. |
domain | String | Yes | β | SIP registrar domain or host (e.g., "sip.domain.com"). |
proxy | String | Yes | "" | Outbound SIP SBC proxy (e.g., "sip:proxy.domain.com:5061"). |
port | String | No | "50061" | SIP server port. |
displayName | String? | No | extension | Display name shown on outgoing calls. |
mobileUser / mobileUsername | String? | No | "agentXX" | Mobile agent identifier for server push token cleanup on logout. Automatically falls back to "agentXX" derived from extension if null. Only required if your PBX uses custom agent usernames. |
userAgent | String? | No | "Pitel VoIP Android" | Custom User-Agent for SIP and PBX API. Automatically sanitized (accents removed, alphanumeric/spaces only, max 30 chars). |
Step 3: Listen to Events & Manage Callsβ
Lifecycle-Aware Observers (Recommended)β
Automatically manages subscription and cleanup according to Android LifecycleOwner (Activity/Fragment):
import com.pitel.voip.sdk.quickstart.observeRegistration
import com.pitel.voip.sdk.quickstart.observeCallState
// Registration status
PitelClient.observeRegistration(lifecycleOwner = this) { status ->
when {
status.isRegistered -> Log.d("VoIP", "Online & Ready")
status.code == 200 -> Log.d("VoIP", "Logged out / Offline")
status.code >= 300 -> Log.e("VoIP", "Registration error: ${status.code}")
}
}
// Call state changes
PitelClient.observeCallState(
lifecycleOwner = this,
onCallStateChanged = { state, duration ->
Log.d("VoIP", "Call state: $state, duration: ${duration}s")
},
onIncomingCall = { callerName, callerNumber ->
Log.d("VoIP", "Incoming call from: $callerName ($callerNumber)")
}
)
Making Outgoing Callsβ
The makeCall method supports both raw extension numbers and full SIP destination URIs. When passing only the extension, the SDK automatically formats the SIP URI using the domain and port from your registered account:
// Option 1: Pass extension directly (SDK auto-formats with registered domain & port)
PitelClient.makeCall("102")
// Option 2: Pass full SIP destination URI
PitelClient.makeCall("sip:102@sip.domain.com:50061")
Ending / Hanging Up Callβ
PitelClient.hangup()
Step 4: Logout (User Signout)β
Unregister the SIP account and revoke device push tokens from PBX/SBC:
PitelClient.logout { result ->
if (result.isSuccess) {
Log.d("VoIP", "Successfully logged out and push tokens cleared.")
} else {
Log.e("VoIP", "Logout failed: ${result.exceptionOrNull()}")
}
}
π‘ Quick Test Helper (For Demo App / Fast Testing Only)β
If you are developing a standalone test app or quick demo where SIP credentials are hardcoded or read directly from a configuration file (such as env.example), you can use PitelQuickStart.setup(...) to run all setup steps in a single call:
import com.pitel.voip.sdk.quickstart.PitelQuickStart
// Auto-runs: init + permissions + FCM token + SIP registration + auto-logout on destroy
PitelQuickStart.setup(
context = this,
extension = "YOUR_EXTENSION",
password = "YOUR_PASSWORD",
domain = "YOUR_DOMAIN",
proxy = "YOUR_PROXY",
port = "50061",
displayName = "YOUR_DISPLAY_NAME",
userAgent = "YOUR_USER_AGENT",
lifecycleOwner = this
)
5. UI Customization (PitelCallUIConfig)β
The SDK provides a built-in Jetpack Compose in-call overlay screen (PitelCallActivity). You can customize the entire appearanceβincluding colors, button visibility, font sizes, text labels, and icon resourcesβusing PitelCallUIConfig:
val customUIConfig = PitelCallUIConfig(
// Colors (Light Mode)
backgroundColor = 0xFF1B2A47, // Dark navy primary background
textColor = 0xFFFFFFFF, // Text color
acceptBtnColor = 0xFF4CAF50, // Green answer button
declineBtnColor = 0xFFE53935, // Red decline button
hangupBtnColor = 0xFFE53935, // Red hangup button
// Custom Status Texts
incomingText = "Incoming call...",
ongoingCallTitle = "Call in progress",
ongoingCallText = "Tap to return to call",
acceptText = "Answer",
declineText = "Decline",
// Visibility Toggles
showKeypadByDefault = false,
showTransferButton = true,
showHoldButton = true,
showMuteButton = true,
showSpeakerButton = true
)
// Apply UI config during initialization
PitelClient.init(
context = this,
autoLaunchCallScreen = true,
uiConfig = customUIConfig
)
PitelCallUIConfig Parameters Referenceβ
| Parameter | Type | Default Value | Description |
|---|---|---|---|
| Theme & Colors (Light Mode) | |||
backgroundColor | Long | 0xFF4F69E3 | Primary call screen background color (HEX ARGB) |
textColor | Long | 0xFFFFFFFF | General text color |
actionCardBgColor | Long | 0xFFFFFFFF | In-call action card panel background color |
| Theme & Colors (Dark Mode) | |||
backgroundColorDark | Long | 0xFF121212 | Primary call screen background color in dark mode |
textColorDark | Long | 0xFFFFFFFF | General text color in dark mode |
actionCardBgColorDark | Long | 0xFF1E1E1E | In-call action card panel background color in dark mode |
| Button States & Colors (Light Mode) | |||
btnActiveBgColor | Long | 0xFFE8ECFF | Active/toggled button background color |
btnInactiveBgColor | Long | 0xFFF5F7FB | Inactive button background color |
btnDisabledBgColor | Long | 0x66F5F7FB | Disabled button background color |
btnActiveIconColor | Long | 0xFF4F69E3 | Active button icon tint |
btnInactiveIconColor | Long | 0xFF2D3748 | Inactive button icon tint |
btnDisabledIconColor | Long | 0xFFA0AEC0 | Disabled button icon tint |
btnLabelTextColor | Long | 0xFF2D3748 | Button label text color |
| Button States & Colors (Dark Mode) | |||
btnActiveBgColorDark | Long | 0xFF3D4E80 | Active button background color in dark mode |
btnInactiveBgColorDark | Long | 0xFF2C2C2E | Inactive button background color in dark mode |
btnDisabledBgColorDark | Long | 0x662C2C2E | Disabled button background color in dark mode |
btnActiveIconColorDark | Long | 0xFF8FA9FF | Active button icon tint in dark mode |
btnInactiveIconColorDark | Long | 0xFFE0E0E0 | Inactive button icon tint in dark mode |
btnDisabledIconColorDark | Long | 0xFF4A4A4A | Disabled button icon tint in dark mode |
btnLabelTextColorDark | Long | 0xFFE0E0E0 | Button label text color in dark mode |
| Control Action Buttons | |||
acceptBtnColor | Long | 0xFF4CAF50 | Answer incoming call button background color |
declineBtnColor | Long | 0xFFE53935 | Decline incoming call button background color |
hangupBtnColor | Long | 0xFFE53935 | Hangup active call button background color |
| Typography & Font Sizes | |||
titleTextSizeSp | Float | 28f | Font size (in SP) for Caller/Callee display name |
| In-Call Action Visibility | |||
showKeypadByDefault | Boolean | false | When true, automatically reveals the DTMF keypad on call start |
showTransferButton | Boolean | true | Show/hide the call transfer button |
showHoldButton | Boolean | true | Show/hide the call hold/unhold button |
showMuteButton | Boolean | true | Show/hide the microphone mute/unmute button |
showSpeakerButton | Boolean | true | Show/hide the audio routing (speaker/earpiece/bluetooth) button |
| Custom Status & Notification Texts | |||
incomingText | String | "Incoming call..." | Incoming call alert title text |
outgoingText | String | "Outgoing..." | Outgoing call dialing status text |
connectingText | String | "Connecting..." | Call connection status text |
ringingText | String | "Ringing..." | Ringing status text |
activeText | String | "Active" | Call established status text |
disconnectedText | String | "Disconnected" | Call ended status text |
acceptText | String | "Answer" | Answer button text in notification popup |
declineText | String | "Decline" | Decline button text in notification popup |
ongoingCallTitle | String | "Call in progress" | Ongoing call notification title |
ongoingCallText | String | "Active call" | Ongoing call notification body text |
Custom Resource Drawables (R.drawable.*) | |||
defaultAvatarResId | Int? | null | Caller avatar placeholder drawable resource ID |
muteIconResId | Int? | null | Mute microphone action button icon |
unmuteIconResId | Int? | null | Unmute microphone action button icon |
speakerIconResId | Int? | null | Speaker audio route button icon |
earpieceIconResId | Int? | null | Earpiece audio route button icon |
bluetoothIconResId | Int? | null | Bluetooth audio route button icon |
headsetIconResId | Int? | null | Wired headset audio route button icon |
holdIconResId | Int? | null | Hold call action button icon |
resumeIconResId | Int? | null | Resume call action button icon |
transferIconResId | Int? | null | Transfer call action button icon |
keypadIconResId | Int? | null | Show dial pad action button icon |
acceptIconResId | Int? | null | Answer call icon |
declineIconResId | Int? | null | Decline call icon |
hangupIconResId | Int? | null | Hangup call icon |
6. Complete Integration Exampleβ
Here is a complete, production-ready MainActivity example demonstrating the standard lifecycle:
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.messaging.FirebaseMessaging
import com.pitel.voip.sdk.core.PitelClient
import com.pitel.voip.sdk.core.PitelCallState
import com.pitel.voip.sdk.quickstart.observeRegistration
import com.pitel.voip.sdk.quickstart.observeCallState
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 1. Initialize SDK
PitelClient.init(
context = this,
autoLaunchCallScreen = true
)
// 2. Request permissions (Microphone, Notifications)
if (!PitelClient.hasRequiredPermissions(this)) {
PitelClient.requestPermissions(this, requestCode = 100)
}
// 3. Register FCM Token
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (task.isSuccessful && task.result != null) {
PitelClient.saveFcmToken(task.result)
}
}
// 4. Attach lifecycle-aware observers
PitelClient.observeRegistration(this) { status ->
if (status.isRegistered) {
Log.d("VoIP", "SIP account online and ready!")
}
}
PitelClient.observeCallState(
lifecycleOwner = this,
onCallStateChanged = { state, duration ->
Log.d("VoIP", "State: $state (${duration}s)")
},
onIncomingCall = { name, number ->
Log.d("VoIP", "Incoming call from $name ($number)")
}
)
// 5. Register account (call when user credentials become available)
loginSipAccount()
}
private fun loginSipAccount() {
PitelClient.registerAccount(
extension = "YOUR_EXTENSION", // e.g., "101"
password = "YOUR_PASSWORD", // e.g., "your_sip_password"
domain = "YOUR_DOMAIN", // e.g., "sip.domain.com"
proxy = "YOUR_PROXY", // e.g., "sip:proxy.domain.com:5061"
port = "50061",
displayName = "YOUR_DISPLAY_NAME"
)
}
fun makeCall(callee: String) {
// Can be just the extension number (e.g. "102") or full SIP URI ("sip:102@domain:50061")
PitelClient.makeCall(callee)
}
fun endCall() {
PitelClient.hangup()
}
fun logout() {
PitelClient.logout { result ->
if (result.isSuccess) {
Log.d("VoIP", "Logged out successfully")
}
}
}
}
7. Licenseβ
Copyright Β© 2024 Tel4vn. All rights reserved.
This SDK is provided under the terms of the Tel4vn Commercial License.
For licensing inquiries, please contact: support@tel4vn.com


