Let's integrate our SDK in few minutes

Quick Start#
Download SDK Files
Download

Audio/Video Call SDKs for Android#

With CONTUS MirrorFly Call SDK for Android, you can efficiently integrate the desired real-time call features into a client app.

When it comes to the client-side implementation, you can initialize and configure the call with minimal efforts. With the server-side, MirrorFly ensures reliable infra-management services for the call within the app. This page will let you know how to install the call SDK in your app.

Note : If you're looking for the fastest way in action with CONTUS MirrorFly Call SDKs, then you need to build your app on top of our sample version. Simply download the sample app and commence your app development. To download sample app click here

Requirements#

The requirements for call SDK for Android are:

  • Android Lollipop 5.0 (API Level 21) or above
  • Java 7 or higher
  • Gradle 4.1.0 or higher

Things to be Noted Before Making a Start#

SDK License Key#

caution

Skip this step if you are already having your license key.

Before integrating CONTUS MirrorFly Call SDK, you need to have a SDK license key for your MirrorFly application. This SDK needs to be authenticated by the MirrorFly server using the license key for further processing.

Follow the below steps to get your license key:

Step 1: Let’s Create an Account - Sign up into MirrorFly Console page (https://console.mirrorfly.com/register) for free MirrorFly account

Step 2: Create an account with your basic details including your name, organization details, work email, and contact number

Step 3: Once you’re in! You get access to your MirrorFly account ‘Overview page’ where you can find a license key as well as downloadable Android SDK for further integration process

Step 4: You can copy the license key from the ‘Application info’ section

license-key

Step 5: To download the AAR files from the Android SDKs, click on ‘Download’ which will take you to the top of the guided documentation page, here, click on the ‘Download button’ and extract the AAR files from the ZIP folder

Step 6: Once finished with the download, now it's time to start with the integration process that begins with creating a new project to develop a call app.

Integrate the Call SDK#

The SDK is already compiled into an AAR file. To use the SDK, the below AAR file has to be imported into the project. To start integrating the SDK's, follow the below steps. If you already integrated the chat sdk initialization only takes adding few additional changes to chat sdk. Call sdk needs kotlin support in your project.

Step 1: Create a new project or Open an existing project in Android Studio

Step 2: Add the following libraries in app/libs folder in the project

  • appbase.aar
  • flycommons.aar
  • flynetwork.aar
  • flydatabase.aar
  • videocompression.aar
  • xmpp.aar
  • flywebrtc.aar

Aarfiles

Step 3: Add the below code in the app/build.gradle file.

plugins {
...
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
packagingOptions {
exclude 'META-INF/AL2.0'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LGPL2.1'
exclude("META-INF/*.kotlin_module")
}
}

Step 4: Add the following dependencies in the app/build.gradle file.

dependencies {
... // your app dependencies
implementation files('libs/appbase.aar')
implementation files('libs/flycommons.aar')
implementation files('libs/flynetwork.aar')
implementation files('libs/flydatabase.aar')
implementation files('libs/videocompression.aar')
implementation files('libs/xmpp.aar')
implementation files('libs/flywebrtc.aar')
}

DependancyAar

Step 5: Add the below dependencies required by the SDK in the app/build.gradle file.

dependencies {
... // your app dependencies
configurations {
all {
exclude group: 'org.json', module: 'json'
exclude group: 'xpp3', module: 'xpp3'
}
}
//For lifecycle listener
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
//For GreenDao
implementation 'de.greenrobot:greendao:2.1.0'
//For gson parsing
implementation 'com.google.code.gson:gson:2.8.1'
//for smack implementation
implementation 'org.igniterealtime.smack:smack-android:4.4.4'
implementation 'org.igniterealtime.smack:smack-tcp:4.4.4'
implementation 'org.igniterealtime.smack:smack-im:4.4.4'
implementation 'org.igniterealtime.smack:smack-extensions:4.4.4'
implementation 'org.igniterealtime.smack:smack-sasl-provided:4.4.4'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.gms:play-services-location:17.0.0'
//Dagger Dependencies
api 'com.google.dagger:dagger:2.40.5'
kapt 'com.google.dagger:dagger-compiler:2.40.5'
api 'com.google.dagger:dagger-android:2.40.5'
api 'com.google.dagger:dagger-android-support:2.40.5'
kapt 'com.google.dagger:dagger-android-processor:2.40.5'
//coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3'
//apicalls
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.squareup.okhttp3:okhttp:4.2.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
//stetho interceptor
implementation 'com.facebook.stetho:stetho-okhttp3:1.3.1'
//okhttp interceptor
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.3'
//shared preference encryption
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
//Socket - versions.gradle
implementation 'com.github.nkzawa:socket.io-client:0.6.0'
//Google - versions.gradle
implementation 'org.webrtc:google-webrtc:1.0.32006'
implementation 'androidx.core:core-ktx:+'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31'
implementation 'androidx.media:media:1.0.0'
//room database
implementation 'androidx.room:room-runtime:2.2.5'
kapt 'androidx.room:room-compiler:2.2.5'
implementation "androidx.room:room-ktx:2.2.5"
// Lifecycle
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'
}

Step 6: Add the below line in the gradle.properties file, to avoid imported library conflicts.

android.enableJetifier=true

Step 7: Add the below line in the setting.gradle file, To resolve webrtc dependencies.

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
}
}

DependancyAar

Step 8: Open the AndroidManifest.xml and add below permissions.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

Configure in app/build.gradle file#

buildTypes {
debug {
buildConfigField 'String', 'SDK_BASE_URL', '"https://api-preprod-sandbox.mirrorfly.com/api/v1/"'
buildConfigField 'String', 'LICENSE', '"xxxxxxxxxxxxxxxxxxxxxxxxx"'
buildConfigField 'String', 'WEB_CHAT_LOGIN', '"https://webchat-preprod-sandbox.mirrorfly.com/"'
buildConfigField "String", "SUPPORT_MAIL", '"contussupport@gmail.com"'
}
}

Initialize Data for Calls#

To start using the call sdk, there are few data that were critical for the Calls SDK to function properly. For which we make use of the ChatSDK builder class to provide data to Calls SDK. In your Application class, inside the onCreate() method use the below ChatSDK Builder to provide the necessary data. An example can be found below.

configscyAar

//For chat logging
LogMessage.enableDebugLogging(BuildConfig.DEBUG);
ChatSDK.Builder()
.setDomainBaseUrl(BuildConfig.SDK_BASE_URL)
.setLicenseKey(BuildConfig.LICENSE)
.setIsTrialLicenceKey(true)
.build();

Chat Builder Function Description#

FunctionParameter TypeDescription
setDomainBaseUrlStringUrl is provided to make API calls
setLicenseKeyStringLicense key is required to proceed with registration
setIsTrialLicenceKeybooleanIf the provided license key is for trial version, display the text as ‘true’ else ‘false’
buildn/aInitializes the chat configuration
caution

The base URL must have the Http/Https protocol which must be closed with a ‘slash (/)’, if not an exception - a bug message will pop up.

Registration#

caution

Skip this step if you are already completed the Registration in your application.

The below method to register a user in sandbox Live mode based on setIsTrialLicenceKey provided.

info

Unless you log out the session, make a note that should never call the registration method more than once in an application

Note: While registration, the below registerUser method will accept the FCM_TOKEN as an optional param and pass it across.

FlyCore.registerUser(USER_IDENTIFIER, (isSuccess, throwable, data ) -> {
if(isSuccess) {
Boolean isNewUser = (Boolean) data.get("is_new_user");
JSONObject responseObject = (JSONObject) data.get("data");
// Get Username and password from the object
} else {
// Register user failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
USER_IDENTIFIERStringA unique Id to Register the User
FCM_TOKENStringA registration token that is generated by FCM SDK for the user's app instance to send message for free
CALLBACKFlyCallbackFlyCallback is used as a callback, implemented and expressed as lambda expression for easy reading

Connect to the Chat Server#

caution

Skip this step if you are already connected to the Chat server in your application.

In order to send messages using the Chat SDK, at first you need to establish the connection to the server. SDK provides methods for initialize the chat connection.

Note: The ChatManager.connect() method should be called only once in an application. SDK will handle the chat server connection and disconnection automatically.

ChatManager.connect(new ChatConnectionListener() {
@Override
public void onConnected() {
// Write your success logic here to navigate Profile Page or
// To Start your one-one chat with your friends
}
@Override
public void onDisconnected() {
// Connection disconnected
//No need implementations
}
@Override
public void onConnectionNotAuthorized() {
// Connection Not authorized
//No need implementations
}
});
ArgumentTypeDescription
CALLBACKChatConnectionListenercallback listener for chat connection

Terminology#

Some of the most common terminologies used in Chat SDK with description

keywordExplanation
userID/userBareIDUnique ID assigned for each user Ex: 12345678 (any alphanumeric). The below characters is not allowed in userId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@) userID should follow below specification: https://xmpp.org/extensions/xep-0106.html
userJid (or) JIDuserID+@+domain of the chat server Ex. 12345678@xmpp.chatsystem.dev.contus.us
groupID/groupBareIDUnique ID assigned for each group Ex: group123456 (any alphanumeric). GroupJID = groupID +@mix.+domain of the chat server Ex: group123456@mix.xmpp.mirrorfly.dev.contus.us`
info

SDK will have built-in functions to prepare the JID, Group JID, and more.

Initialize Call SDK#

In your Application class, inside the onCreate() method add the below lines:

ArgumentTypeDescription
CALL_UI_ACTIVITYClassActivity which needs to be invoked during incoming call. when a incoming call is received Call sdk will start this activity with the call details
@Override
public void onCreate() {
super.onCreate();
//Initialize call manager
CallManager.init(this);
//set your call activity
CallManager.setCallActivityClass(CALL_UI_ACTIVITY.class);
CallManager.setMissedCallListener((isOneToOneCall, userJid, groupId, callType, userList) -> {
//show missed call notification
});
CallManager.setCallHelper(new CallHelper() {
@NonNull
@Override
public String getNotificationContent(@NonNull String callDirection) {
return CallNotificationHelper.getNotificationMessage();
}
@Override
public void sendCallMessage(@NotNull GroupCallDetails details, @NotNull List<String> users, @NotNull List<String> invitedUsers) {
CallMessenger.sendCallMessage(details, users, invitedUsers);
}
});
CallManager.setCallNameHelper(new CallNameHelper() {
@NonNull
@Override
public String getDisplayName(@NonNull String jid) {
return ContactManager.getDisplayName(jid);
}
});
}

Note: setCallNameHelper is optional, if it is not configured then user name will be empty in the incomming and ongoing call notification.

Setup your call activity#

Call UI Activity should be defined like below in your manifest

<activity
android:name="YOUR_CALL_ACTIVITY"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:resizeableActivity="false"
android:screenOrientation="portrait"
android:supportsPictureInPicture="true"
android:showOnLockScreen="true"
android:turnScreenOn="true"
android:taskAffinity="call.video"
tools:targetApi="o_mr1" />

You need to call the below method on your call activityonCreate() to configure the call activity.

CallManager.configureCallActivity(ACTIVITY);
ArgumentTypeDescription
ACTIVITYActivityinstance of the call activity

You need to call the below method on onStart() from your call activity to notify the call sdk to remove the ongoing call notification.

CallManager.bindCallService();

You need to call the below method on onStop() from your call activity to notify the call sdk to show the ongoing call notification.

CallManager.unbindCallService();

Make a call#

Call feature is essential for the modern day communication. Call sdk allows users to make a one to one audio/video call with the another sdk user.

Note: You need to check the required runtime permissions before calling call sdk methods. if required permissions are not available isSuccess will be false and error message will be given in callback.

Required runtime permissions#

For audio call, we need a below permissions:

Manifest.permission.RECORD_AUDIO
Manifest.permission.READ_PHONE_STATE

You can use the below method to check audio call permissions:

CallManager.isAudioCallPermissionsGranted();

From Android 12, ensure that android.permission.BLUETOOTH_CONNECT and android.permission.READ_PHONE_STATE runtime permissions are granted for your app for seameless audio routing and gsm call handling. If the android.permission.BLUETOOTH_CONNECTpermission is not granted, call audio will not be routed to BT Headset even though it is connected. If the android.permission.READ_PHONE_STATE permission is not granted, gsm call related functionalities will not work in sdk.

Make a voice call#

Make voice call feature allows users to make a one to one audio call with the another sdk user. You can make a voice call using the below method.

CallManager.makeVoiceCall("TO_JID", (isSuccess, message) -> {
});
ArgumentTypeDescription
TO_JIDStringjid of the call receiver
CALLBACKCallActionListenercallback to observe the action status

Receive a call#

Whenever you receive the audio call from the another sdk user, call sdk will show notification if device android version is greater than or equal to Android 10 (API level 29), otherwise the activity which you set using the CallManager.setCallActivityClass() method during call sdk initialisation will be started with the call details. sample call ui will be available for quick integration.

caution

Please don't forget to set activity class for call sdk using CallManager.setCallActivityClass().

Answer the call#

Whenever you receive the audio call from the another sdk user, depending upon the android version, you activity may be started so whenever user presses accept button from your call UI , you need to call the below sdk method to answer the call and notify the caller.

Note: if the required permissions are not available then call be will be automatically declined even though you answered a call

ArgumentTypeDescription
CALLBACKCallActionListenercallback to observe the action status
CallManager.answerCall((isSuccess, message) -> {
});

Decline the call#

Whenever you receive the audio call from the another sdk user, depending upon the android version, you activity may be started so whenever user presses decline button from your call UI , you need to call the below sdk method to decline the call and notify the caller.

CallManager.declineCall();

Disconnect the ongoing call#

Whenever you make the audio call to the another sdk user and you just want to disconnect the call before getting connected or if you want to just disconnect a connected call after the end of conversation, whenever user presses the disconnect button from your call UI , you need to call the below sdk method to disconnect the call and notify the caller.

Note: The below method accepts CallActionListener as a optional paramter. you can pass the listener to get disconnect success callback

CallManager.disconnectCall();