Skip to content

The #1 Custom CPaaS Video, Audio & Chat APIs. MirrorFly enables an easy and fast integration of standard CPaaS Solution like messaging, voice and video call features in new or existing apps.

Notifications You must be signed in to change notification settings

MirrorFly/MirrorFly-Android-Sample

Repository files navigation

MirrorFly Android SDK For Video Chat & Calls

MirrorFly provides the chat and call API & SDK for your Android apps, allowing you to add real-time messaging and calling capabilities to your platform. The development kit comes with 1000+ custom CPaaS features along with 500+ AI-powered features to automate the conversational flow across your app.

Every component in the kit is customizable letting developers build custom communication workflow with the freedom to host the solution on any server. Along with this, the security features can also be customized to add additional layers of data encryption. The entire platform can be white-labeled, without mention of the provider, enabling a fully branded experience to users.

🤹 Key Product Offerings

MirrorFly helps build omni-channel communication apps for any kind of business

💬 In-app Messaging - Connect users individually or as groups via instant messaging features.
🎯 HD Video Calling- Engage users over face-to-face conversations anytime, and from anywhere.
🦾 HQ Voice Calling - Deliver crystal clear audio calling experiences with latency as low as 3ms.
🤖 AI Voice Agent - Build custom AI voicebots that can understand, act and respond to user questions.
🤖 AI Chatbot - Deploy white-label AI chatbots that drive autonomous conversations across any web or mobile app.
🦾 Live Streaming - Broadcast video content to millions of viewers around the world, within your own enterprise app.

With CONTUS MirrorFly Chat SDK for Android, you can easily add real-time chat features to your client app within 30 minutes.

Through our client SDK, you can initialize and configure chat into your app with minimal efforts.

Note : If you're looking for the fastest way to build your app’s UI with MirrorFly Chat SDKs, you can use our sample apps. To get our sample apps, click here

The requirements for chat SDK for Android are:

  • Android Lollipop 5.0 (API Level 21) or above
  • Java 7 or higher
  • Gradle 8.6.0 or higher
  • Kotlin 2.0.20 or higher
  • targetSdkVersion, compileSdk 35

Note : If you're utilizing Chat SDK version 7.13.27 or higher, it's must to set the target SDK version to 35. This is due to the migration of Chat SDK to Android 15.

SDK License Key

To integrate MirrorFly Chat SDK into your app, you will need a SDK License Key. The MirrorFly server will use this license key to authenticate the SDK in your application.

Step 1: Register here to get a MirrorFly User account.
Step 2: Login to your Account
Step 3: Get the License key from the application Info’ section

![chat messaging sdk for android][image2]

Step 1: Create a new project or open an existing project in Android Studio.
Step 2:

  • If you are using Gradle 6.8 or higher, add the following code to your settings.gradle file.
  • If you are using Gradle 6.7 or lower, add the code to your root build.gradle file.
dependencyResolutionManagement {
    repositories {
        mavenCentral()
        google()
        jcenter()
        maven {
            url "https://repo.mirrorfly.com/release"
        }
    }
}

![Jcenter][image3]

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

dependencies {
    implementation 'com.mirrorfly.sdk:mirrorflysdk:7.13.31'
}

Step 4: Add the following line to your gradle.properties file to prevent conflicts with imported libraries:

android.enableJetifier=true

Step 5: Open the AndroidManifest.xml file and add the following permissions:

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

Before you start using the SDK, ensure you meet some basic requirements. In your Application class, within the onCreate() method, use the following ChatManager method to provide the necessary initialization data:

![configscyAar][image4]

ChatManager.initializeSDK("LICENSE_KEY", (isSuccess, throwable, data) -> {
    if (isSuccess) {
        Log.d("TAG", "initializeSDK success ");
    } else {
        Log.d("TAG", "initializeSDK failed with reason " + data.get("message"));
    }
});

Add the created MyApplication 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=".MyApplication"  <!-- 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>
</manifest>

The following method registers a user in sandbox or live mode based on the setIsTrialLicenceKey setting.

FlyCore.registerUser(USER_IDENTIFIER, (isSuccess, throwable, data) -> {
    if (isSuccess) {
        Boolean isNewUser = (Boolean) data.get("is_new_user"); // true - if the current user is different from the previous session's logged-in user, false - if the same user is logging in again
        String userJid = (String) data.get("userJid"); // Ex. [email protected] (USER_IDENTIFIER + @ + domain of the chat server)
        JSONObject responseObject = (JSONObject) data.get("data");
        String username = responseObject.getString("username");
    } else {
        // Register user failed print throwable to find the exception details.
    }
});

Once registration is successful, the Chat SDK automatically attempts to connect to the chat server. It also monitors application lifecycle changes and connects or disconnects from the chat server accordingly.

Once the ChatConnectionListener is set, you can receive connection status updates through the callback method shown below.

ChatManager.setConnectionListener(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
    }

    @Override
    public void onConnectionFailed(@NonNull FlyException e) {
        // Connection Not authorized or Unable to establish connection with server
    }

    @Override
    public void onReconnecting() {
        // Automatic reconnection enabled
    }
});

To generate a JID for any user, use the below method.

FlyUtils.getJid(USER_NAME);

Use the below method to send a text message to other user,

TextMessage textMessage = new TextMessage();
textMessage.setToId(TO_JID);
textMessage.setMessageText(TEXT);
FlyMessenger.sendTextMessage(textMessage, (isSuccess, error, chatMessage) -> {
    if (isSuccess) {
        // you will get the message sent success response
    }
});

You need to initialize the MessageEventsListener observer to receive and monitor all incoming messages sent to you.

ChatEventsManager.setupMessageEventListener(new MessageEventsListener() {
    @Override
    public void onMessageReceived(@NotNull ChatMessage message) {
        // called when the new message is received
    }
});

These listeners are triggered only when a new message is received from another user. For more details, refer to the callback listeners documentation.

@Override
public void onMessageReceived(@NonNull ChatMessage message) {
    super.onMessageReceived(message);
    // received message object
}

Making a call

The call feature is essential for modern communication. The Call SDK enables users to make one-to-one audio or video calls with other SDK users.

For audio call, we need a below permissions:

Manifest.permission.RECORD_AUDIO
Manifest.permission.READ_PHONE_STATE

You can use the below method to check audio call permissions:

CallManager.isAudioCallPermissionsGranted();

For video call, we need below permissions:

Manifest.permission.RECORD_AUDIO
Manifest.permission.CAMERA
Manifest.permission.READ_PHONE_STATE

You can use the below method to check video call permissions:

CallManager.isVideoCallPermissionsGranted();

You can use the below method to check call notification permission:

Manifest.permission.POST_NOTIFICATIONS
CallManager.isNotificationPermissionsGranted();

To send custom data when making a call, use the optional metaData parameter in all makeCall methods. This parameter accepts an array of type CallMetadata.

The voice call feature allows users to make a one-to-one audio call with another SDK user, including optional call metadata. Use the following method to initiate a voice call:

CallManager.makeVoiceCall("TO_JID", CALL_METADATA, (isSuccess, flyException) -> {
    if (isSuccess) {
        // SDK will take care of presenting the Call UI. It will present the activity
        // that is passed using the method `CallManager.setCallActivityClass()`
        Log.d("MakeCall", "call success");
    } else {
        if (flyException != null) {
            String errorMessage = flyException.getMessage();
            Log.d("MakeCall", "Call failed with error: " + errorMessage);
            // toast error message
        }
    }
});

The video call feature allows users to make a one-to-one video call with another SDK user, including optional call metadata. Use the following method to initiate a video call:

CallManager.makeVideoCall("TO_JID", CALL_METADATA, (isSuccess, flyException) -> {
    if (isSuccess) {
        // SDK will take care of presenting the Call UI. It will present the activity
        // that is passed using the method `CallManager.setCallActivityClass()`
        Log.d("MakeCall", "call success");
    } else {
        if (flyException != null) {
            String errorMessage = flyException.getMessage();
            Log.d("MakeCall", "Call failed with error: " + errorMessage);
            // toast error message
        }
    }
});

The group voice call feature allows users to make a voice call with multiple SDK users, including optional call metadata. Use the following method to initiate a group voice call:

CallManager.makeGroupVoiceCall(JID_LIST, GROUP_ID, CALL_METADATA, new CallActionListener() {
    @Override
    public void onResponse(boolean isSuccess, @Nullable FlyException flyException) {
        if (isSuccess) {
            // SDK will take care of presenting the Call UI. It will present the activity
            // that is passed using the method `CallManager.setCallActivityClass()`
            Log.d("MakeCall", "call success");
        } else {
            if (flyException != null) {
                String errorMessage = flyException.getMessage();
                Log.d("MakeCall", "Call failed with error: " + errorMessage);
                // toast error message
            }
        }
    }
});

The group video call feature allows users to make a video call with multiple SDK users, including optional call metadata. Use the following method to initiate a group video call:

CallManager.makeGroupVideoCall(JID_LIST, GROUP_ID, CALL_METADATA, new CallActionListener() {
    @Override
    public void onResponse(boolean isSuccess, @Nullable FlyException flyException) {
        if (isSuccess) {
            // SDK will take care of presenting the Call UI. It will present the activity
            // that is passed using the method `CallManager.setCallActivityClass()`
            Log.d("MakeCall", "call success");
        } else {
            if (flyException != null) {
                String errorMessage = flyException.getMessage();
                Log.d("MakeCall", "Call failed with error: " + errorMessage);
                // toast error message
            }
        }
    }
});

After a call is connected, you can add users to the ongoing call. The SDK provides methods to invite users, and once they accept the incoming call, they will join the active call.

CallManager.inviteUsersToOngoingCall(JID_LIST, new CallActionListener() {
    @Override
    public void onResponse(boolean isSuccess, @Nullable FlyException flyException) {
        // handle invite result
    }
});

When you receive an audio or video call from another SDK user, the Call SDK will display a notification if the device is running Android 10 (API level 29) or higher. For lower Android versions, the activity set via CallManager.setCallActivityClass() during SDK initialization will launch with the call details. A sample call UI is also provided for quick integration.

When you receive an audio or video call from another SDK user, your activity may be launched depending on the Android version. When the user presses the accept button in your call UI, call the following SDK method to answer the call and notify the caller.

CallManager.answerCall((isSuccess, flyException) -> {
    if (isSuccess) {
        Log.d("AnswerCall", "call answered success");
    } else {
        if (flyException != null) {
            String errorMessage = flyException.getMessage();
            Log.d("AnswerCall", "Call answered failed with error: " + errorMessage);
            // toast error message
        }
    }
});

When you receive an audio or video call from another SDK user, your activity may be launched depending on the Android version. When the user presses the decline button in your call UI, call the following SDK method to decline the call and notify the caller.

CallManager.declineCall();

Whenever you make an audio or video call to another SDK user and want to disconnect either before the call connects or after the conversation ends, call the following SDK method when the user presses the disconnect button in your call UI. This will end the call and notify the other participant.

CallManager.disconnectCall();

☁️ Deployment Models - Self-hosted and Cloud

MirrorFly offers full freedom with the hosting options:
Self-hosted: Deploy your client on your own data centers, private cloud or third-party servers.
Check out our multi-tenant cloud hosting
Cloud: Host your client on MirrorFly’s multi-tenant cloud servers.
Check out our multi-tenant cloud hosting

Mobile Client

MirrorFly offers a fully-built client SafeTalk that is available in:

  • iOS
  • Android

📚 Learn More

🧑‍💻 Hire Experts

Need a tech team to build your enterprise app? Hire a full team of experts. From concept to launch, we handle every step of the development process. Get a high-quality, fully-built app ready to launch, carefully built by industry experts

⏱️ Round-the-clock Support

If you’d like to take help when working with our solution, feel free to contact our experts who will be available to help you anytime of the day or night.

💼 Become a Part of our amazing team

We're always on the lookout for talented developers, support specialists, and product managers. Visit our careers page to explore current opportunities.

🗞️ Get the Latest Updates

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •