This tutorial will discuss the steps to use MirrorFly SDKs to implement messaging features into any Android app. With a focus of explaining the development of apps that can run on both mobile and web apps, we have used Java as the primary language all through this guide.
Before getting started, here is an overview of messaging features that you can add to your apps with our messaging SDKs:
MirrorFly developed messaging APIs & SDKs that can be integrated into an app to enable chat features like one-to-one messaging, group chats and notifications. Here is a list of key features you can use integrate by connecting your app to the chat features in MirrorFly’s SDKs:
Explore more features from MirrorFly here
Step 1 : first step in the integration process is to create an account with MirrorFly.
Step 2 : In the Registration Page, fill in your details and click on the Signup button to create your MirrorFly account.
Step 3 : Once your profile is created, you will be taken you to your Account’s Overview page
Step 4 : Kindly make a note of the License Key under the Application Info Section
Step 5 : Next, scroll down and you will be able to find MirrorFly’s SDKs available for download.
Step 6 : Since we will be integrating the SDKs into Android App, Click on the Download SDK adjacent to Android.
Step 7 : The downloaded ZIP folder will contain the AAR files comprising the SDK features.
Step 8 : At the end of this step, you will have the following requirements ready with you.
If you have decided on creating an online chat application in Java using API or SDK integration, you have 2 choices - to use our sample app or build your app using Android Studio IDE.
Download our Sample App here
If you are creating your own chat app, you can find the initial steps of the set up process using Android Studio Below:
Let’s declare it’s time for the integration now!
appbase.aar
Flycommons.aar
flynetwork.aar
flydatabase.aar
videocompression.aar
flywebrtc.aar
Xmpp.aar
Your Project will now look as follows:
Next, add the following codes 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")
}
}
Specify the implementation configuration in the dependencies block of the build.gradle module.
These configurations request different library dependencies for unique purposes.
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')
}
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'
}
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
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"'
}
}
//For chat logging
LogMessage.enableDebugLogging(BuildConfig.DEBUG);
ChatSDK.Builder()
.setDomainBaseUrl(BuildConfig.SDK_BASE_URL)
.setLicenseKey(BuildConfig.LICENSE)
.setIsTrialLicenceKey(true)
.build();
After initializing the chat SDK and configuring the chat and group builder functions, integrate the code to register a new user. Use the below code for implementing the registration process in your app. During this process, the registerUser method accepts the FCM_TOKEN as an optional parameter.
Request Parameters:
Argument | Type | Description |
---|---|---|
USER_IDENTIFIER | String | Unique Id to Register the User |
FCM_TOKEN | String | fcm device token |
CALLBACK | FlyCallback | FlyCallback implemented as lambda expression |
Code:
FlyCore.registerUser(USER_IDENTIFIER, FCM_TOKEN, (isSuccess, throwable, data ) -> {
if(isSuccess) {
JSONObject responseObject = (JSONObject) data.get("data");
// Get Username, password and Auth token from the object
} else {
// Register user failed print throwable to find the exception details.
}
});
A connection between the integrations in the app and the server is needed to send and receive messages. To achieve this, we need to configure the method server.sdk. This method stores the connection details and automatically connects the integrations to the server every time you open the app.
Connection Initialization:
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
}
});
This method is used to configure your chat app for sending text messages. During this process, you must call the username method username as String userJID = FlyUtils.getJid(USERNAME)
Request Parameters
Argument | Type | Description |
---|---|---|
TO_JID | String | JID of the end user |
TEXT | String | Indicates the text message that needs to be sent |
CALLBACK | SendMessageListener | callback to observe the action status |
Code:
Use the following code to enable sending text message from your app:
FlyMessenger.sendTextMessage(TO_JID, TEXT, new SendMessageListener() {
@Override
public void onResponse(boolean isSuccess, @Nullable ChatMessage chatMessage) {
// you will get the message sent success response
}
});
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 { }
Here, the listeners would be called only when a new message is received from other users.
@Override
public void onMessageReceived(@NonNull ChatMessage message) {
super.onMessageReceived(message);
// received message object
}
You’ve come to the end of this tutorial! You have now learned how to build video calling into Android apps with the help of MirrorFly SDKs using Kotlin as the programming language.
To access the full-length code of this tutorial, check out our Github repo here . If you’ll need any help with the SDK installation, write to us here and our team of experts will get back to you at the earliest. Happy developing!
Start & Build Your Android Chat App With 150+ Chat Features & 10+ Monetize Models
Integrate Our Video, Voice & Chat SDKs into any app in < 30 mins
Contact SalesGet Full Access To Our Customizable Video, Voice & Chat SDKs!
Request Demo