Introduction

This tutorial is prepared to help developers understand the process of integrating MirrorFly’s messaging SDKs into a client app.

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

MirrorFly has developed and designed the SDKs based on a clear research on developer’s needs when building a chat app. There’s no doubt that every module speaks for itself. The SDKs are built with utmost focus on providing full-fledged communication features to chat apps. We would be more than happy to support you during the implementation of our features into your apps. Also, we’d like to widen our horizons with every new requirement you demand of us. Talk to our experts now!

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
Try it free
#
Ready to Get Started with Our FREE Chat APIs?

Create immersive chat, video & voice calling experiences that skyrocket engagement and increase your app stickiness with our APIs & SDKs.

  • Dedicated Cloud Server
  • API Response 3 Seconds
  • 99.999% Uptime SLA
Try it free *No Credit Card Required Contact Sales