Let's integrate our SDK in few minutes

Quick Start#
Download SDK Files
Download
warning

MirrorFly Chat SDK V1 is no longer supported as a new version is released. Check out our latest Chat SDK V2 here.

To migrate from MirrorFly Chat SDK V1 to V2 please follow the Migration guide steps.

Chat SDKs for Android#

With CONTUS MirrorFly Chat SDK for Android, you can easily add real-time chat features to your client app within 30 minutes.

Through our client SDK, you can initialize and configure chat into your app with minimal efforts.

Note : If you're looking for the fastest way to build your app’s UI with MirrorFly Chat SDKs, you can use our sample apps. To get our sample apps, click here

Integrate the Chat SDK#

Requirements#

The requirements for chat 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 You Get Started#

SDK License Key#

To integrate MirrorFly Chat SDK into your app, you will need a SDK License Key. The MirrorFly server will use this license key to authenticate the SDK in your application.

To get the License Key,#

Step 1: Register here to get a MirrorFly User account. Registration is subject to verification and would take up to 24 hours.

Step 2: Login to your Account

Step 3: Get the License key from the application Info’ section

Step 4: Download the Android SDK

Getting Started#

As soon as the AAR files have been imported from the zip file using Kotlin, you can start over with the integration process.

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

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')
}

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.6')
implementation ('org.igniterealtime.smack:smack-tcp:4.4.6')
implementation 'org.igniterealtime.smack:smack-im:4.4.6'
implementation 'org.igniterealtime.smack:smack-extensions:4.4.6'
implementation 'org.igniterealtime.smack:smack-sasl-provided:4.4.6'
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.8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8'
//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'
//for mobile number formatting
implementation 'io.michaelrocks:libphonenumber-android:8.10.1'
}

Step 6: Add the below line in the project level build.gradle file, to resolve library dependencies.

Jcenter

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

android.enableJetifier=true

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" />

Configure in app/build.gradle file#

You can copy the license key from the 'Overview’ section in the Console dashboard.

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 Chat SDK#

To start using the sdk, there is a need for some basic requirements before proceeding with the initialization process. Thus, the ChatSDK builder class is used to provide the necessary data to the SDK. In your Application class, inside the onCreate() method use the below ChatSDK Builder to provide the necessary data.

configscyAar

//For chat logging
LogMessage.enableDebugLogging(BuildConfig.DEBUG);
new 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#

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,USER_TYPE and FORCE_REGISTER 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. We accept only the AlphaNumeric String
FCM_TOKENStringA registration token that is generated by FCM SDK for the user's app instance to send message for free
FORCE_REGISTERbooleandefault value true provide true to force the logout of the old session If the registered user has reached the maximum no of multi-sessions or provide false to allow registration till the maximum no of multi-sessions
USER_TYPEStringtype of the user
CALLBACKFlyCallbackFlyCallback is used as a callback, implemented and expressed as lambda expression for easy reading
caution

If FORCE_REGISTER is false and it reached the maximum no of multi-sessions then registration will not succeed it will throw a 405 exception, Either FORCE_REGISTER should be true or one of the existing session need to be logged out to continue registration.

Connect to the Chat Server#

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.

Send a One-to-One Message#

Use the below method to send a text message to other user,

Note: To generate a unique user id, you must call the other user's username method String userJID = FlyUtils.getJid(USERNAME)

FlyMessenger.sendTextMessage(TO_JID, TEXT, new SendMessageListener() {
@Override
public void onResponse(boolean isSuccess, @Nullable ChatMessage chatMessage) {
// you will get the message sent success response
}
});
ArgumentTypeDescription
TO_JIDStringJID of the end user
TEXTStringIndicates the text message that needs to be sent
REPLY_MESSAGE_IDStringSpecifies the Message ID of replied message
CALLBACKSendMessageListenercallback to observe the action status

Receive a One-to-One Message#

You can extend the FlyBaseActivity from SDK into your app BaseActivity, and observe all the incoming messages and other feature listeners.

public class MainActivity extends FlyBaseActivity { }

Moreover, here the listeners would be called only when a new message is received from other user. To get more details please visit this callback listeners

@Override
public void onMessageReceived(@NonNull ChatMessage message) {
super.onMessageReceived(message);
// received message object
}