Integrate the Chat SDK

Step 1: Add the following to your root build.gradle file.

allprojects {
repositories {
maven {url "https://repo.mirrorfly.com/snapshot"}
}
}

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

android {
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")
}
}
dependencies {
configurations {
all {
exclude group: 'org.json', module: 'json'
exclude group: 'xpp3', module: 'xpp3'
}
}
implementation 'com.mirrorfly.sdk:appbase:0.0.10'
}

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

android.enableJetifier=true

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

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

STEP 4:Download flysdk and extract the Android supporing files and move into Android project

  • FlyBaseController.kt
  • FlyEvent.kt

Configure in app/build.gradle file#

android {
compileSdkVersion 33
....
....
defaultConfig {
....
....
minSdkVersion 21
targetSdkVersion 33
}
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#

Create Android Application#

In Android porject create a new class called MyApplication and copy the below code snippet in the MyApplication file.

class MyApplication : FlutterApplication() {
init {
instance = this
}
companion object {
private var instance: MyApplication? = null
fun getContext(): Context {
return instance!!.applicationContext
}
}
override fun onCreate() {
super.onCreate()
}
}

Add the following override methods in your Android main activity#

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
FlyBaseController(this).init(flutterEngine);
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
FlyBaseController(this).onActivityResult(requestCode, resultCode, data)
}
override fun onResume() {
super.onResume()
FlyBaseController(this).onResume()
}
override fun onDestroy() {
super.onDestroy()
FlyBaseController(this).onDestroy()
}

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 Android Application class, inside the onCreate() method use the below ChatSDK Builder to provide the necessary data.

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