Android

I. Setting up Android Studio project

Step 1: Download portsipSDK here .

Step 2 : Unzip the downloaded .zip file, copy the fileAndroid projectAndroidSample/SIPSample_AndroidStudio/SIPSample/libs/portsipvoipsdk.jarfolderapp/libs

Step 3 : Compile Libs: Right click on the fileportsipvoipsdk.jarand selectAdd as Library...

Step 4 : Declare the necessary permissions in the fileAndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
  <!-- Các permission liên quan đến internet. -->
  
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <!-- Allows the application to unlock the phone when there is an incoming call. -->
  <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
  <!-- Allows the application to open fullscreen interface when receiving incoming call notification
when the phone is in inactive state (lock screen, kill app, not in application screen) -->
  <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
  <!-- Allows users to operate when the device is in locked state (press to accept/reject calls). -->
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <!-- Allow use of microphone. -->
  <uses-permission android:name="android.permission.CAMERA" />
  <!-- Allow use of camera. -->
  <uses-permission android:name="android.permission.VIBRATE" />
  <!-- Allows the application to control the phone to vibrate when there is an incoming call. -->

</manifest>

Reference : https://www.portsip.com/docs/sdk/manual/portsip-voip-sdk-user-manual-android.pdf

The examples from section II onwards apply to two files: MainActivity.kt and PortsipService.kt

II. Initialize SDK

In filePortsipService.kt

  • Declare global variable val portsipSDK: PortSipSdk = PortSipSdk(). Used to call PortsipSDK APIs.

  • Class PortsipService phải implement interface: **OnPortSIPEvent .**

This function should be called together with extension login.

III. Extension login

First, in the file MainActivity.kt, we have to launch it PortsipServicefirst.

In the file PortsipService.kt, after startServicestep 1 onStartCommandis PortsipServicerun, the extension login can be called at this time, implemented as the following example

There should be a variable portsipRegisteredto save the status of whether the portip has been registered successfully or not. If the registration is successful, just call the API refreshRegistration(), no need to go through the 2 steps initialSDK()above registerPortsip().

If you want to re-register from the beginning, you must initialize the SDK again as in section II .

There are 2 events that will occur when logging in to an extension:

IV. Log out of extension

In filePortsipService.kt

V. Making an outgoing call

In filePortsipService.kt

  • To make a call :

  • When the call recipient accepts the call:

Event onInviteAnswered()occurs.

When the call recipient rejects the call/the call is not answered/or for some reason the call is unsuccessful:

event onInviteFailure()occurs

Actively end the call:

VI. Receive call (incoming call)

Mobile Push (push notification voip) needs to be applied so that the application can receive calls in inactive cases:

  • User not on application screen

  • Lock screen

  • Kill app

6.1. Set up mobile push

To use mobile push, you need to declare your Android application with the portsip system through the following steps:

  • Get 2 information: 1 Server Key and 1 Sender ID on Firebase of Project.

  • applicationIdlocated in the build.gradle (Module: android.app)example file: vn.etelecom.app

  • Send this information to eTelecom 3 to create additional Mobile Push.

6.2. Reality

  • When there is a call to the extension :

Event onInviteIncoming()occurs.

  • Create a service called FirebaseService, and declare it inAndroidManifest.xml

FirebaseService.kt

AndroidManifest.xml

  • build.gradle(Project: android), add the following classpath:

  • build.gradle(Module: android.app), add dependencies as follows:

Create notification channel: to use for notification of incoming calls. We should call this function at the same time as logging in to the extension.

When onStartCommandthe operation PortsipServiceis run, it is detailed in section III.

  • When the Firebase token is refreshed:

  • When you kill the app, or turn off the phone screen, incoming calls will be fired through Firebase and will be processed here:

  • When starting the application, the first time we start PortsipService, we have to listen for the Firebase token and then log in to the extension.

  • The function refreshPushTokencan be implemented as follows:

  • The function showPendingNotificationcan be implemented as follows:

Some actions the user can perform when receiving a call: Accept (pick up the phone), Reject, Hang up (after accepting), etc...

VII. Video call

There needs to be an Activity that represents the Video call, for example:

You should use the portsipSDK variable in the file PortsipService.ktto avoid creating multiple instances of a variable, which will cause many unwanted bugs.

The interface of the above Activity can be implemented in a file video_call_view.xmlas shown in the following example:

Make and receive calls :

Last updated