In this tutorial, you will learn how to use the MirrorFly SDK coded in Kotlin, for implementing video calling features to Android apps. To get started, we take you through the steps to download our SDKs and then explain the integration process in the Android Studio IDE. At the end, we will show you the steps to connect the client app and the SDK server, to implement the direct messaging functionality.
Here is a quick-list of requirements we’ll use to build the video calling app:
There are two ways you can add our SDKs to your video call app
Let’s get started!
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.
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" / >
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
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()
To implement sending and receiving calls, the SDKs need permissions for both audio and video. They are explained in the below section:
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();
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) {
}
})
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) })
})
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.
2 primary actions will be performed when an user (callee) accepts an incoming call:
We will use the following codes to achieve this:
CallManager.answerCall(object : CallActionListener {
override fun onResponse(isSuccess: Boolean, message: String) {
}
})
})
When a callee declines the call before answering it,
Use the below code to establish this:
CallManager.declineCall()
For an user to be able to disconnect an ongoing call, use the below code:
CallManager.disconnectCall()
That’s it! We hope this article helped you understand the steps to implement chat into your android apps using Java. As you can see, it is trivial and easy to build powerful in-app communication features with MirrorFly SDKs.
If you’d like to extend your app functionality with more interactive chat features, our SDKs offer a wide range of options. Talk to our experts for more details.
Start today with MirrorFly APIs and services to scale 1 Billion+ Conversations.
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