Notes
New changes for the Android SDK
- The new SDK has breaking changes for the method to register an endpoint.
- The SDK is backward compatible.
Terminology
- username: username of an endpoint
- password: password of an endpoint
- token: device token for VoIP push notifications. You can obtain a device token from APNS by registering for push notifications.
- certificateId: certificate ID created in the Plivo console under Voice > Push Credentials — see push credentials documentation.
Register an endpoint
Declare or use user input for the endpoint and password from the console
Instantiate the Endpoint class
- With options
- Without options
Log in with an FCM token after fetching it from Firebase Cloud Messaging
Log in with an FCM token from Firebase and a certificate ID from console
Log in without an FCM token
Examples of basic call actions
Make an outbound call
To make an outbound call, use this code.Receive a call
Implement EventListener on your class and override the onIncomingCall method using the command:Note: See our documentation on Setting Up Push Notification for more information on implementing incoming calls in an Android app.
Autoconnect when the network is available
Note: Don’t attach an external NetworkChangeReceiver. It’s now part of client-sdk and taken care of by the SDK.
Configuration parameters
Attribute | Description | Allowed Values | Default Value |
---|---|---|---|
debug | Enable log messages. | true, false | false |
enableTracking | Set to true if you want to get MediaMetrics events and enable call quality tracking. | true, false | true |
maxAverageBitrate | Controls your application’s bandwidth consumption for calls. A high maxAverageBitrate value yields better audio quality but may result in more bandwidth consumption. Lowering maxAverageBitrate impacts call quality as the audio is compressed to reduce bandwidth consumption. This parameter applies only to calls using the Opus codec. See RFC-7587 section 7.1 for more info. | 8000 – 48000 | 48000 |
enableQualityTracking | This parameter can be used to enable and disable two functionalities: MediaMetrics events: enables the client device to display local call issues like broken audio, etc., to the user. Call quality tracking: enables Plivo to capture and display call quality data in Call Insights. When set to all , both MediaMetrics events and call quality tracking are enabled.When set to remoteonly only call quality tracking is enabled.When set to localonly only MediaMetrics events are enabled.When set to none both MediaMetrics events and call quality tracking are disabled. | CallAndMediaMetrics.ALLCallAndMediaMetrics.NONE CallAndMediaMetrics.REMOTE_ONLY CallAndMediaMetrics.LOCAL_ONLY | CallAndMediaMetrics.ALL |
Classes and methods
Class: Endpoint
The Endpoint class lets you register a Plivo SIP endpoint, after which you can make and receive calls using it.Creates the endpoint objects:
- @param context — Application/Activity context.
- @param debug — Setting this to
true
turns on the Plivo SDK debug logs. Default isfalse
. - @param eventListener — Login, Call events Callback listener.
Method: login (String username, String password, String fcmToken, String certificateID)
Note: This is the recommended login method to enable incoming calls using push notifications.
- username — The username of the endpoint created on Plivo
- password — The password of the endpoint created on Plivo
- fcmToken — Device token obtained from Firebase. The FCM token is needed to alert the user about incoming calls using Firebase push notifications.
- certificateID — Certificate ID created in the console after uploading push credentials. See our documentation on Setting Up Push Notification.
usage
Method: login(String username, String password, String fcmToken)
- username — The username of the endpoint created on Plivo
- password — The password of the endpoint created on Plivo
- fcmToken — Device token obtained from Firebase. The FCM token is needed to alert the user about incoming calls using Firebase push notifications.
usage
Note: This method has been deprecated. We do not recommend using this method. Use setRegTimeout() function instead. The endpoint will not be able to accept incoming calls if it’s logged in using this method.
public setRegTimeout(int timeout)
Method: login(String username, String password, int regTimeout)
Note: This login method has a limitation: Incoming calls may not work if the app goes to the background.
- username — The username of the endpoint created on Plivo
- password — The password of the endpoint created on Plivo
- regTimeout — Seconds to reregister if the app is in the foreground. The allowed value range is 120 to 86,400. The default is 600.
usage
With Access Tokens/ JWT
You can register an endpoint using:- Access Token, device token, and certificate ID
- Access Token, and device token
- Access Token
- Access Token Generator
Method: loginWithJwtToken(String JWTToken)
Note: This login method has a limitation: Incoming calls may not work if the app goes to the background.
- JWTToken — The JWT you can generate via server-side API or via JWT creator
usage
Method: loginWithJwtToken(String JWTToken, String deviceToken)
- JWTToken — The JWT you can generate via server-side API or via JWT creator.
- deviceToken — Device token obtained from Firebase. The FCM token is needed to alert the user about incoming calls using Firebase push notifications.
Usage
Method: loginWithJwtToken(String JWTToken, String deviceToken, String certificateId)
- JWTToken — The JWT you can generate via server-side API or via JWT creator.
- deviceToken — Device token obtained from Firebase. The FCM token is needed to alert the user about incoming calls using Firebase push notifications.
- certificateId — Certificate ID created in the console after uploading push credentials. See section below on Setting Up Push Notification.
Usage
Method: loginWithJwtToken(String JWTToken, String deviceToken, String certificateId)
- AccessTokenListener — This listener consists of an only method getAccessToken(). Implement it if you want to get notified for existing token expiry.
usage
Note: This relayVoipPushNotification() method has been deprecated and will be removed in future releases. We do not recommend using this method. Use loginForIncomingWithUsername() function when logged in with username/password or loginForIncomingWithJwt() function when logged in with JWT Access Token instead.
Method: relayVoipPushNotification(Map<String, String> notification)
This method forwards FCM notification data to the Plivo SDK. The onIncomingCall() method is called after calling this function. When the app is in the killed state and wakes up from the FCM notification, call login(username, password, deviceToken) before calling relayVoipPushNotification(remoteMessage.getData()).usage
When receiving a push notification from FCM, check whether the endpoint is logged in. If it’s not, call login(username, password, deviceToken) then call relayVoipPushNotification(remoteMessage.getData()).Method: loginForIncomingWithUsername(String username, String password, String certificateId, HashMap<String, String> incomingData)
- username — The username of the endpoint created on Plivo
- password — The password of the endpoint created on Plivo
- certificateID — Certificate ID created in the console after uploading push credentials. See section below on Setting Up Push Notification.
- incomingData — Notification data from FCM.
usage
When receiving a push notification from FCM, no need to check whether the endpoint is logged in.Method: loginForIncomingWithJwt(String deviceToken, String jwtToken, String certificateId, HashMap<String, String> incomingData)
- token — Device token obtained from Firebase. The FCM token is needed to alert the user about incoming calls using Firebase push notifications.
- JWTToken — The JWT you can generate via server-side API or via JWT creator.
- certificateID — Certificate ID created in the console after uploading push credentials. See section below on Setting Up Push Notification.
- incomingData — Notification data from FCM.
usage
When receiving a push notification from FCM, no need to check whether the endpoint is logged in.Method: logout
This method unregisters an endpoint.usage
Method: createOutgoingCall
Calling this method returns an Outgoing object linked to the registered endpoint that can be used to make outbound calls. Calling this method on an unregistered PlivoEndpoint object returns null.usage
Method: submitCallQualityFeedback
- callUUID — Mandatory string parameter used to identify the call the feedback belongs to. You can get the callUUID for the last call using getLastCallUUID().
-
starRating — Mandatory integer parameter with a value from 1 to 5. For a score from 1 to 4, the
issues
parameter is mandatory; for a score of 5 it’s optional. -
issueList — IssueList is an array and must have at least one of these reasons for a
starRating
value from 1 to 4 —AUDIO_LAG
,BROKEN_AUDIO
,CALL_DROPPPED
,CALLERID_ISSUES
,DIGITS_NOT_CAPTURED
,ECHO
,HIGH_CONNECT_TIME
,LOW_AUDIO_LEVEL
,ONE_WAY_AUDIO
,ROBOTIC_AUDIO
,OTHERS
- Comments — Optional string attribute for users remarks; maximum length 280 characters.
-
sendConsoleLogs — Optional boolean parameter with default value
false
. Set totrue
to let Plivo’s team collect and analyze Android SDK logs for a better understanding of an issue. - callback — This is the FeedbackCallback instance that accesses the onFailure, onSuccess, and onValidationFail callback methods.
usage
Method: getCallUUID
usage
Class: Outgoing
The Outgoing class contains methods to make and control an outbound call.Method: call
usage
Method: mute
usage
Method: unmute
usage
Method: sendDigits
usage
Method: hangup
usage
Class: Incoming
The Incoming class contains methods to handle an incoming call. The public void onIncomingCall(Incoming incoming) eventListener receives an object of this class. These are the methods available in the Incoming class.Method: answer
usage
Method: mute
usage
Method: unmute
usage
Method: sendDigits
usage
Method: hangup
usage
Method: reject
usage
Class: EventListener
These are the methods available in the EventListener class.Method: onLogin
usage
Method: onLoginFailed
usage
INVALID_ACCESS_TOKEN
, INVALID_ACCESS_TOKEN_HEADER
, INVALID_ACCESS_TOKEN_ISSUER
, INVALID_ACCESS_TOKEN_SUBJECT
, ACCESS_TOKEN_NOT_VALID_YET
, ACCESS_TOKEN_EXPIRED
, INVALID_ACCESS_TOKEN_SIGNATURE
, INVALID_ACCESS_TOKEN_GRANTS
, EXPIRATION_EXCEEDS_MAX_ALLOWED_TIME
, MAX_ALLOWED_LOGIN_REACHED
usage
Method: onPermissionDenied
usage
Method: onIncomingCall
usage
Method: onIncomingCallConnected
Note: Call incomingCall.answer() or incomingCall.reject() only after receiving the onIncomingCallConnected event.
Method: onIncomingCallRejected
usage
Method: onIncomingCallHangup
usage
Method: onIncomingDigitNotification
usage
Method: onOutgoingCall
usage
Method: onOutgoingRinging
usage
Method: onOutgoingCallAnswered
usage
Method: onOutgoingCallHangup
usage
Method: onOutgoingCallRejected
usage
Method: mediaMetrics
For an ongoing call, if any of the below events are triggered, the MediaMetrics listener will be called with the values of the event in the mediaMetrics object. To enable this feature, set the enableTracking flag totrue
during endpoint initialization.
MediaMetrics Events
Events | Description | Example |
---|---|---|
high_jitter | When jitter is higher than 30 milliseconds for two out of the last three samples. This event is generated individually for the local stream and remote stream. | \{ group: 'network', level: 'warning', type: 'high_jitter', active: true/false, // false when the value goes to normal level (two out of last three samples have jitter less than 30 ms) value: '\<average jitter value>', desc: 'high jitter detected due to network congestion, can result in audio quality problems', stream: 'local || remote' } |
high_rtt | When round-trip time (RTT) is higher than 400 milliseconds for two out of the last three samples. | \{ group: 'network', level: 'warning', type: 'high_rtt', active: true/false, // false when value goes to normal level (two out of last three samples have RTT less than 400 ms) value: '\<average rtt value>', desc: 'high latency detected, can result in delay in audio', stream: 'None' } |
high_packetloss | When the packet loss is > 10%. This event is generated individually for the local stream and remote stream. | `{ group: ‘network’, level: ‘warning’, type: ‘high_packetloss’, active: true/false, // false when value goes to normal level value: ‘<average packet loss value>’, desc: ‘high packet loss is detected on media stream, can result in choppy audio or dropped call’, stream: ‘local || remote’ } |
low_mos | When sampled mean opinion score (MOS) is < 3.5 for two out of the last three samples. | \{ group: 'network', level: 'warning', type: 'low_mos', active: true/false, // false when value goes to normal level. value: '\<current_mos_value>', desc: 'low Mean Opinion Score (MOS)', stream: 'None' } |
no_audio_received | When remote or local audio is silent. This event is generated individually for the local stream and remote stream. | \{ group: 'audio', level: 'warning', type: 'no_audio_received', active: true/false, // false when value goes to normal level value: '\<current_value_in_dB>', desc: 'no audio packets received' stream: 'local || remote' } |
Setting up push notification
This section explains how to receive incoming calls on the Plivo Android SDK using Firebase. To receive an incoming call, you must:- Create a project on Firebase.
- Register your app on Firebase.
- Add the Firebase config file and Firebase SDK into your app.
- Copy the Firebase service account token to the Plivo Dashoboard.
Create a project on Firebase
On the Firebase console, click Add project. Specify a project name and click Create project.
Register your app on Firebase
Go to the Android section of your project home page and register your Android package on Firebase.
Add the Firebase config file and SDK into your app
Download the Firebase google-services.json file.


Copy the Firebase service accounts token to the Plivo Dashoboard
In settings of the project, the token file is shown under the Service Accounts tab. Clicking on ‘Generate new pair key’ will download the file

FCM
.

Resources
FAQ
- Where can I see an example app that shows how to use the Android SDK to make calls?
- The PlivoSimpleQuickStart app shows how to use the Android SDK with minimum code.
- How can I file support tickets or report issues? Create a ticket on our support portal. Include the details below to help us debug issues quickly.
- Description of your use case (app backgrounded, on Wi-Fi/mobile data, lot of network fluctuations)
- Plivo SDK Verbose Logs (Android application logs)
- Plivo will look for logcat logs that starts with “D/PlivoEndpoint” or “E/PlivoEndpoint”
-
All SIP transactions, such as
- Plivo callUUID (for instance, Call-ID:352231d3-3ea9-40c8-8259-e4843f5b02fc)
- Plivo SDK version
- Plivo SDK methods call flows, such as:
- endpoint.login();
- outgoing.callH(num, headers);
- Android device version (for instance, Android 12.1.0_r11)
- Android device model (for example, Samsung Galaxy S22 Plus)
Best practices
- Don’t use deprecated methods, because they will be prone to crashes and NoMethodError when removed in the future.
- Use the deviceToken while logging in to get an incoming call via push notification instead of using the background service to run forever in the background and watch for incoming calls.