Introduction

In this tutorial, you will learn how to implement group video calls to your Android app using MirrorFly’s SDK. We will use Kotlin as the programming language for the SDK integration process and Android Studio as the IDE.

Requirements

Preparing the App

There are two ways you can add our SDKs to your video call app

  • Integrate the package to your existing App
  • Use our Sample App

Let’s get started!

Installation of the App Dependencies

System Requirements:

  • Kotlin
  • Android Studio

Install the App Dependencies:

Step 1 : Open your Android Studio IDE

Step 2 : Create a new project or open an existing project.

Step 3 : Next, add the following libraries to your project’s app/libs folder. This step will download the library files from your MirrorFly SDK files and add them to your project.

  • flycommons.aar
  • flynetwork.aar
  • flywebrtc.aar

Step 4 : Continue to add the following dependencies to the app/build.gradle file


                      implementation files('libs/flycommons.aar')
                      implementation files('libs/flynetwork.aar')
                      implementation files('libs/flywebrtc.aar')
                  

Step 4 : The SDK files will require the dependencies as follows:


                  //Socket - versions.gradle
                   implementation 'com.github.nkzawa:socket.io-client:0.6.0'
                  //Google - versions.gradle
                  implementation 'org.webrtc:google-webrtc:1.0.32006'
                  //okhttp interceptor
                  implementation 'com.squareup.okhttp3:logging-interceptor:3.14.3'
                  implementation 'androidx.core:core-ktx:+'
                  implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31'
                  //coroutines
                  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
                  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3'
                  implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
                  implementation 'androidx.media:media:1.0.0' 
                  //room database
                  implementation 'androidx.room:room-runtime:2.2.5'
                  kapt 'androidx.room:room-compiler:2.2.5'
                  implementation "androidx.room:room-ktx:2.2.5" 
                  // Lifecycle
                  implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
                  kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'
                  //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'
                  

Step 5 : In the app level build gradle, add the following codes:


                             //Socket - versions.gradle
                             implementation 'com.github.nkzawa:socket.io-client:0.6.0'
                             //Google - versions.gradle
                             implementation 'org.webrtc:google-webrtc:1.0.32006'
                             //okhttp interceptor
                             implementation 'com.squareup.okhttp3:logging-interceptor:3.14.3'
                             implementation 'androidx.core:core-ktx:+'
                             implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31'
                             //coroutines
                             implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
                             implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3' 
                             implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
                             implementation 'androidx.media:media:1.0.0' 
                             //room database
                             implementation 'androidx.room:room-runtime:2.2.5'
                             kapt 'androidx.room:room-compiler:2.2.5'
                             implementation "androidx.room:room-ktx:2.2.5" 
                             // Lifecycle
                             implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
                             kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'
                             //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'  
                             dependencies { 
                               configurations {
                                  all {
                                     exclude group: 'org.json', module: 'json'
                                     exclude group: 'xpp3', module: 'xpp3'
                                      }
                                      }
                                     } 
                                    ```  
                          

Step 5 : Add the below permissions in AndroidManifest.xml:


                                    <uses-permission android:name="android.permission.INTERNET" / >
                                    <uses-permission android:name="android.permission.RECORD_AUDIO" / >
                                    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" / >
                                    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" / >
                                    <uses-permission android:name="android.permission.CAMERA" / >
                                    <uses-permission android:name="android.permission.READ_PHONE_STATE" / >
                                    <uses-permission android:name="android.permission.WAKE_LOCK" / >
                            

Setting Up the MirrorFly SDK

Add the below lines in the oncreate() method of your application class:

 
                     @Override
                     public void onCreate() {
                        super.onCreate();
                        //initialize call sdk
                        CallManager.init(this)
                        CallManager.setCurrentUserId(SharedPreferenceManager.instance.currentUserJid)
                        CallManager.setSignalServerUrl(SIGNAL_SERVER_DOMAIN)
                        CallManager.setJanusWebSocketServerUrl(JANUS_WEBSOCKET_SERVER_DOMAIN)
                        CallManager.setCallActivityClass(CALL_UI_ACTIVITY::class.java)
                        CallManager.setIceServers(ICE_SERVERS_LIST)
                        CallManager.setMissedCallListener(object : MissedCallListener {
                  override fun onMissedCall(isOneToOneCall: Boolean, userJid: String, groupId: String?, callType: String, 
                  userList: ArrayList?) {
                     //show missed call notification
                     }
                     }) 
                     CallManager.setCallHelper(object : CallHelper {
                         override fun getDisplayName(jid: String): String {
                         return ContactManager.getDisplayName(jid)
                          } 
                          override fun getNotificationContent(callDirection: String): String {
                         return CallNotificationHelper.getNotificationMessage()
                         } 
                         override fun isDeletedUser(jid: String): Boolean {
                         return ContactManager.getProfileDetails(jid)?.contactType == ContactType.DELETED_CONTACT
                        } 
                         override fun sendCallMessage(details: GroupCallDetails, users: List, invitedUsers: List) {
                          CallMessenger.sendCallMessage(details, users, invitedUsers)
                         }
                         }) 
                         ChatManager.callService = WebRtcCallService::class.java
                  

Setting Up Your Call Activity

In your manifest, define the Call UI Activity as follows:


                     <activity
                      android:name="YOUR_CALL_ACTIVITY"
                      android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
                      android:excludeFromRecents="true"
                      android:launchMode="singleTask"
                      android:resizeableActivity="false"
                      android:screenOrientation="portrait"
                      android:supportsPictureInPicture="true"
                      android:showOnLockScreen="true"
                      android:turnScreenOn="true"
                      android:taskAffinity="call.video"
                       tools:targetApi="o_mr1" />  
                     

Configure the call activity using the below method on onCreate()


                     CallManager.configureCallActivity()
                     

In order to notify the call SDK to remove the ongoing call notification call the onStart() method from your call activity.

show the ongoing call notification


                     CallManager.unbindCallService()
                     

Making a Call

To implement sending and receiving calls, the SDKs need permissions for both audio and video. They are explained in the below section:

Runtime Permissions:

Add the manifest permission as follows:


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

To check the video call permissions:


                         CallManager.isVideoCallPermissionsGranted();
                        

Make a Group Video Call

Once the permissions are checked, the following code is used to add the group video calling functionality:


                          CallManager.makeGroupVideoCall(JID_LIST, GROUP_ID, object : CallActionListener{
                             override fun onResponse(isSuccess: Boolean, message: String) {
                              }
                              }) 
                          

Add Participants to the Call

Use the below code to add participants to an ongoing call:

Argument Type Description
JID_LIST List >String< jid list of the callee's

                                CallManager.inviteUsersToOngoingCall(JID_LIST) }) 
                                    }) 
                          

Receiving a Incoming Audio/Video Call

If you are using a device with version greater than Android 10, the call SDK will notify an incoming call. Otherwise, you will have to set the CallManager.setCallActivityClass() during the SDK initialization.

Answer the Incoming Call

2 primary actions will be performed when an user (callee) accepts an incoming call:

  • The call gets answered
  • The caller will be notified that the call has been accepted by the callee

We will use the following codes to achieve this:


                           CallManager.answerCall(object : CallActionListener {
                              override fun onResponse(isSuccess: Boolean, message: String) {
                                 }
                                 })
                                 }) 
                          

Decline the Incoming Call

When a callee declines the call before answering it,

  • The call connection must be stopped
  • The call must be notified on the call decline

Use the below code to establish this:


                          CallManager.declineCall()
                          

Disconnect the Ongoing Call

For an user to be able to disconnect an ongoing call, use the below code:


                          CallManager.disconnectCall()
                          

Conclusion

Although this tutorial has covered only the initial steps of the group video call integration, you will be able to add the following functionalities using our SDK.

  • Call Muting
  • Camera Switching
  • Moderation
  • Call Quality Configurations
  • Call Quality Configurations

And the list does not stop here. Click to explore more.

Launch your Own Android & iOS Group Video Call App with Kotlin!

Start today with MirrorFly APIs and services to scale 1 Billion+ Conversations.

  • 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