Skip to main content

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)
Native Call ScreenLockscreen FullscreenHeads-up Notification
Integrated Compose in-call screenIncoming call on lockscreenIncoming call heads-up notification banner

πŸ“š Documentation Index​

GuideDescription
πŸš€ Step-by-Step Integration GuideStandard 4-step lifecycle integration with PitelClient.
🎨 UI Customization GuideComplete theme colors, dark mode, button icons, and custom text labels.
πŸ€– Android Push NotificationsFirebase setup, service account, custom FirebaseMessagingService, and cURL test.
πŸ›‘οΈ Full-Screen Intent GuideAndroid 14+ FSI compliance, lockscreen call presentation, and Google Play policy.
🌐 Web Portal Setup GuideConfigure app identifiers and upload Firebase credentials to Pitel Portal.
πŸ“– SIP Status Codes ReferenceSIP disconnect codes, causes, and call end handling.
πŸ› οΈ Troubleshooting GuideSolutions for registration errors, audio routing, permissions, and network issues.

1. System Requirements​

  • Android SDK 24+
  • targetSdkVersion >= 33
  • Firebase configured for Android (google-services.json file placed in your app's app/ directory).
  • Google Services Gradle Plugin (com.google.gms.google-services) applied to your app module.

2. Library Installation​

NOTE

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:

  1. In your settings.gradle.kts:

    include(":pitel-voip-sdk")
  2. In your app/build.gradle.kts dependencies:

    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:

  1. Configure GitHub Packages credentials in your settings.gradle.kts or root build.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
    }
    }
    }
    }
  2. 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")
    }
IMPORTANT

Firebase Setup & Pitel Portal Configuration:

  • Place your own Firebase project's google-services.json file inside your application's app/ directory (app/google-services.json).
  • You must configure your Firebase Service Account credentials on the Pitel Web Portal matching your applicationId so 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>
NOTE

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_INTENT internally 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​

ParameterTypeRequiredDefaultDescription
contextContextYesβ€”Application or Activity context.
fcmTokenStringYes*β€”FCM device registration token (required to receive incoming calls; pass here or via saveFcmToken).
mobileUsernameString?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").
userAgentString?No"Pitel VoIP Android"Custom User-Agent header (automatically sanitized to max 30 alphanumeric characters).
autoLaunchCallScreenBooleanNotrueWhen true, automatically reveals the native in-call screen overlay upon connected calls.
uiConfigPitelCallUIConfigNoPitelCallUIConfig()Visual styling configuration for colors, buttons, texts, and icons.
incomingCallModeIncomingCallModeNoFULLSCREENPresentation mode: FULLSCREEN (lockscreen activity) or NOTIFICATION (heads-up banner).
IMPORTANT

* 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 fcmToken parameter in the initial init call.
  • HOWEVER, YOU MUST call PitelClient.saveFcmToken(token) as soon as Firebase returns the token (and inside onNewToken), before calling PitelClient.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:

ModeBehaviorRequirements / 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.NOTIFICATIONDisplays 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​

ParameterTypeRequiredDefaultDescription
extensionStringYesβ€”SIP extension/username (e.g., "101").
passwordStringYesβ€”SIP account password.
domainStringYesβ€”SIP registrar domain or host (e.g., "sip.domain.com").
proxyStringYes""Outbound SIP SBC proxy (e.g., "sip:proxy.domain.com:5061").
portStringNo"50061"SIP server port.
displayNameString?NoextensionDisplay name shown on outgoing calls.
mobileUser / mobileUsernameString?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.
userAgentString?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​

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​

ParameterTypeDefault ValueDescription
Theme & Colors (Light Mode)
backgroundColorLong0xFF4F69E3Primary call screen background color (HEX ARGB)
textColorLong0xFFFFFFFFGeneral text color
actionCardBgColorLong0xFFFFFFFFIn-call action card panel background color
Theme & Colors (Dark Mode)
backgroundColorDarkLong0xFF121212Primary call screen background color in dark mode
textColorDarkLong0xFFFFFFFFGeneral text color in dark mode
actionCardBgColorDarkLong0xFF1E1E1EIn-call action card panel background color in dark mode
Button States & Colors (Light Mode)
btnActiveBgColorLong0xFFE8ECFFActive/toggled button background color
btnInactiveBgColorLong0xFFF5F7FBInactive button background color
btnDisabledBgColorLong0x66F5F7FBDisabled button background color
btnActiveIconColorLong0xFF4F69E3Active button icon tint
btnInactiveIconColorLong0xFF2D3748Inactive button icon tint
btnDisabledIconColorLong0xFFA0AEC0Disabled button icon tint
btnLabelTextColorLong0xFF2D3748Button label text color
Button States & Colors (Dark Mode)
btnActiveBgColorDarkLong0xFF3D4E80Active button background color in dark mode
btnInactiveBgColorDarkLong0xFF2C2C2EInactive button background color in dark mode
btnDisabledBgColorDarkLong0x662C2C2EDisabled button background color in dark mode
btnActiveIconColorDarkLong0xFF8FA9FFActive button icon tint in dark mode
btnInactiveIconColorDarkLong0xFFE0E0E0Inactive button icon tint in dark mode
btnDisabledIconColorDarkLong0xFF4A4A4ADisabled button icon tint in dark mode
btnLabelTextColorDarkLong0xFFE0E0E0Button label text color in dark mode
Control Action Buttons
acceptBtnColorLong0xFF4CAF50Answer incoming call button background color
declineBtnColorLong0xFFE53935Decline incoming call button background color
hangupBtnColorLong0xFFE53935Hangup active call button background color
Typography & Font Sizes
titleTextSizeSpFloat28fFont size (in SP) for Caller/Callee display name
In-Call Action Visibility
showKeypadByDefaultBooleanfalseWhen true, automatically reveals the DTMF keypad on call start
showTransferButtonBooleantrueShow/hide the call transfer button
showHoldButtonBooleantrueShow/hide the call hold/unhold button
showMuteButtonBooleantrueShow/hide the microphone mute/unmute button
showSpeakerButtonBooleantrueShow/hide the audio routing (speaker/earpiece/bluetooth) button
Custom Status & Notification Texts
incomingTextString"Incoming call..."Incoming call alert title text
outgoingTextString"Outgoing..."Outgoing call dialing status text
connectingTextString"Connecting..."Call connection status text
ringingTextString"Ringing..."Ringing status text
activeTextString"Active"Call established status text
disconnectedTextString"Disconnected"Call ended status text
acceptTextString"Answer"Answer button text in notification popup
declineTextString"Decline"Decline button text in notification popup
ongoingCallTitleString"Call in progress"Ongoing call notification title
ongoingCallTextString"Active call"Ongoing call notification body text
Custom Resource Drawables (R.drawable.*)
defaultAvatarResIdInt?nullCaller avatar placeholder drawable resource ID
muteIconResIdInt?nullMute microphone action button icon
unmuteIconResIdInt?nullUnmute microphone action button icon
speakerIconResIdInt?nullSpeaker audio route button icon
earpieceIconResIdInt?nullEarpiece audio route button icon
bluetoothIconResIdInt?nullBluetooth audio route button icon
headsetIconResIdInt?nullWired headset audio route button icon
holdIconResIdInt?nullHold call action button icon
resumeIconResIdInt?nullResume call action button icon
transferIconResIdInt?nullTransfer call action button icon
keypadIconResIdInt?nullShow dial pad action button icon
acceptIconResIdInt?nullAnswer call icon
declineIconResIdInt?nullDecline call icon
hangupIconResIdInt?nullHangup 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