Let's integrate our UIKIT in few minutes

Mirrorfly UIKit Sdk is a set of prebuilt UI components that allows you to easily integrate an in-app chat with all the essential messaging features. Our development kit includes light and dark themes, text fonts, colors and more. You can customize these components to create an interactive messaging unique interface.

Requirements#

The requirements for chat SDK for Android are:

  • Android Marshmallow 6.0 (API Level 23) or above
  • Java 8 or higher
  • Gradle 4.1.0 or higher

Things to be Noted Before Making a Start#

SDK License Key#

Before integrating CONTUS MirrorFly Chat 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.

To get the License Key,#

Step 1: Sign up for a MirrorFly Account

Step 2: Log into your Account

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

license-key

Integration#

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

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

plugins {
...
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
id 'androidx.navigation.safeargs'
}
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")
}
buildFeatures {
viewBinding = true
}
dataBinding {
enabled = true
}
}

Note : In case "The 'kotlin-android-extensions' Gradle plugin is no longer supported" then remove the 'kotlin-android-extensions' from app/build.gradle plugins".

Step 3: If using Gradle 6.8 or higher, add the following code to your settings.gradle file. If using Gradle 6.7 or lower, add the following code to your root build.gradle file. See this release note to learn more about updates to Gradle.

dependencyResolutionManagement {
repositories {
jcenter()
maven {
url "https://repo.mirrorfly.com/snapshot"
}
}
}

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

dependencies {
implementation 'com.mirrorfly.uikitsdk:mf-uikitsdk:1.0.16'
}

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

buildscript {
dependencies {
def nav_version = "2.3.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}

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

android.enableJetifier=true

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Initialization#

To integrate and run Mirrorfly UIKit in your app, you need to initialize it first. You can initialize the MirrorFlyUIKit instance by passing the MirrorFlyUIKitAdapter instance as an argument to a parameter in the MirrorFlyUIKit.init() method. The MirrorFlyUIKit.init() must be called once in the onCreate() method of your app’s Application instance.

Then provide your APP_NAME BASE_URL LICENCE_KEY isCallEnabled = false and If you have subscription set isTrialLicenceKey true else set isTrialLicenceKey false

This BASE_URL and LICENCE_KEY can be obtained from 'Overview' section from the Console dashboard.

package com.example.mfuikittest
import android.app.Application
import com.mirrorflyuikitsdk.MirrorFlyUIKit
import com.mirrorflyuikitsdk.adapter.MirrorFlyUIKitAdapter
class BaseApplication : Application() {
override fun onCreate() {
super.onCreate()
MirrorFlyUIKit.initFlySDK(applicationContext,object : MirrorFlyUIKitAdapter {
override fun setAppName(): String? {
return "YOUR_APP_NAME"
}
override fun setBaseUrl(): String {
return "YOUR_BASE_URL"
}
override fun setLicence(): String {
return "YOUR_LICENCE_KEY"
}
override fun isCallEnabled(): Boolean {
return true
}
override fun isContactEnable(): Boolean? {
return true
}
override fun isGroupEnable(): Boolean? {
return true
}
override fun isOtherProfileEnable(): Boolean? {
return true
}
override fun isOwnProfileEnable(): Boolean? {
return true
}
override fun isTrialLicenceKey(): Boolean? {
return true
}
override fun setGoogleTranslationKey(): String? {
return "YOUR_GOOGLE_TRANSLATION_KEY"
}
override fun setApplicationID(): String? {
return "YOUR_APPLICATION_ID"
}
})
MirrorFlyUIKit.defaultThemeMode = MirrorFlyUIKit.ThemeMode.Light
}
}
ArgumentTypeDescription
YOUR_APP_NAMEStringset your application name
YOUR_APPLICATION_IDStringset your application id
YOUR_BASE_URLStringset your base url
YOUR_LICENCE_KEYStringset your licence key
YOUR_GOOGLE_TRANSLATION_KEYStringset your Translation key
isTrialLicenceKeyBooleanset true or false
isContactEnableBooleanset true or false
isCallEnabledBooleanset true or false
isGroupEnableBooleanset true or false
isOwnProfileEnableBooleanset true or false
isOtherProfileEnableBooleanset true or false

Add BaseApplication#

Add the created BaseApplication to AndroidManifest.xml.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uikitapplication">
<application
android:name=".BaseApplication" // Add this line.
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
...
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Note : Use the "Theme.MaterialComponents.DayNight.NoActionBar" in the style.xml or themes.xml to avoid the app bar in the call screen.

Registration#

The below method to register a user.

info

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

Note : Use the Mirrorfly UIKIt SDK registration function after your application login process.

MirrorFlyUIKit.initUser("USER_IDENTIFIER", "FIREBASE TOKEN", object : InitResultHandler {
override fun onInitResponse(isSuccess: Boolean, e: String) {
if (isSuccess) {
Log.d("TAG", "onInitResponse called with: isSuccess = $isSuccess")
} else {
Log.e("TAG", "onInitResponse called with: Failure, e = $e")
}
}
})
ArgumentTypeDescription
USER_IDENTIFIERStringUnique Id to Register the User
FIREBASE TOKENStringFirebase Token for Message and Call Push Notification

Display Recent Chat and Call list#

DashBoardActivity is the starting point for launching UIKit in your application. By implementing the code below, you will see a complete list of recent chats that you're made with single and group conversation.

Note : Use DashBoardActivity only when you have done the registration.

package com.custom.mfuikittest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.mirrorflyuikitsdk.activities.DashBoardActivity
class MainActivity : DashBoardActivity() { // Add this line.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// If you’re going to inherit `DashBoardActivity`, don’t implement `setContentView()`
}
}

Sending a message#

You can now run the application on an emulator or a plugged-in device. To send a message, you must first start a conversation by clicking on the icon in the top-right corner. Then, you can select the user you wish to chat. Once navigated to user chat screen, type your first message and press send.

Recent & Single Chat#

recent_single_chat_light