Introduction

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 - Messaging Features Overview

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:

  • Send / Receive Text Messages
  • Attach Files / Images or Media
  • Message Status
  • Forward Messages
  • Group Creation
  • Add / Remove Participants
  • Recent Chats
  • Unread Messages Count
  • Last received Message
  • Call Update in Push Notification Tray

Explore more features from MirrorFly here

Setting up MirrorFly Account

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.

  • SDK Download
  • License Key

Preparing the App

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.

Basic Requirements

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

Sample App

Download our Sample App here

SDK Integration

  • Let’s assume your project name here is ‘My_First_App’
  • In the main menu, navigate to the Gradle Scripts > build.gradle
  • You will find 2 build.gradle files here: A project module build.gradle (Project: My_First_App) and an app module build.gradle (Module: My_First_App.app)
  • As you build the app, configuring each app module will help you control the gradle plugin that is responsible for adding several features specific to your app requirements.

Step 3: Configuration

  • In the Builder Configuration, update the License Key acquired from your MirrorFly account.

                      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"'
                      }
                      }
                    
  • On updating the Key, perform the gradle sync operation. This will look through the dependencies you’ve listed in the build.gradle and will download the specified version.
  • During the gradle sync, ensure to have an internet connection and check the ports in gradle.properties to avoid sync failures.
  • We will be using the following Chat Builder Functions in the upcoming integration steps

Step 4: Initialization

  • Once the necessary dependencies are added, we need to provide the data needed to start using the SDK.
  • For this, you need to perform the following:
    • Add the builder class ChatSDK
    • Call onCreate() method to start the SDK in the Application class
#
  • Add the following code:

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

Note: Make sure that you set your local path folder name in .setMediaFolderName to maintain the app’s media files. If the path is not changed from SELECT_YOUR_PATH_NAME), by default, the folder name will be assigned as MirrorFly

Step 5: User Registration

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.
                                    }
                                    });
                          

Step 6: Establishing Connection to Chat Server

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

Step 7: Send One-to-One Text Message

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

Step 8: Receive Text Messages

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
                       }   
                    

Conclusion

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!

Looking To Build An Android Chat App?

Start & Build Your Android Chat App With 150+ Chat Features & 10+ Monetize Models

  • Average API response 3s
  • 100ms worldwide latency
  • 1 Billion+ Conversations
Contact Sales
#
Integrate Our SDKs In Just 20 Mins!

Integrate Our Video, Voice & Chat SDKs into any app in < 30 mins

Contact Sales
#
Get Started With Our Self-hosted Chat Solution Today!

Get Full Access To Our Customizable Video, Voice & Chat SDKs!

Request Demo
Request Demo
Need to build a complete chat app? Let our experts help you out.
Hire Our Team