Integration

This document describes how to rapidly integrate the TUICallKit component. You can complete the following key steps within 10 minutes and obtain a complete audio and video call interface.


Preparations

Environmental Requirements

Android version requirements: Android 5.0 (SDK API Level 21) and above version
Gradle version requirements: Gradle 4.2.1
Device requirements: Android 5.0 or higher mobile devices.

Activating Service

Before using the audio and video service provided by Tencent Cloud, go to the console to activate the service for your application. For specific steps, see Activating the ervice. After enabling the service, record the SDKAppID and SDKSecretKey, which will be used in subsequent steps(login).

Implementation

Step 1.Importing Components

Clone or download the code from GitHub, then copy the tuicallkit-kt subdirectory under the Android directory to your current project at the same directory level as the app, as shown below.


Step 2.Project Configuration

1. In the project root directory, find the settings.gradle.kts (or settings.gradle) file and add the following code to import the tuicallkit-kt component into the project.
setting.gradle.kts
settings.gradle
include(":tuicallkit-kt")
include ':tuicallkit-kt'
2. Locate the build.gradle.kts (or build.gradle) file under the app directory, and add the following code in dependencies to declare the app's dependency on the component.
build.gradle.kts
build.gradle
dependencies {
api(project(":tuicallkit-kt"))
}
dependencies {
api project(':tuicallkit-kt')
}
Note:
The TUICallKit project internally depends on TRTC SDK,IM SDK,tuicallengine and public library tuicore by default. Developers do not need to configure them separately. If needed, just modify the version number in tuicallkit-kt/build.gradle file to upgrade.
3. Since the SDK internally uses Java reflection feature, some classes need to be added to the non-obfuscation list. Please add the following code at the end of the proguard-rules.pro file under the app directory. After that, click Sync Now in the upper right corner to synchronize the code.
-keep class com.tencent.** { *; }
4. In the app directory, find the AndroidManifest.xml file, add tools:replace="android:allowBackup" in the application node, overwrite the settings within the component, and use your own settings.
// app/src/main/AndroidManifest.xml
<application
android:name=".BaseApplication"
android:allowBackup="false"
android:icon="@drawable/app_ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup">

Step 3.Login

Add the following code in your project. It enables logging in to the TUI component by calling the relevant APIs in TUICore. This procedure is critical. Only after a successful login can you properly use the features provided by TUICallKit.
login
Android(Kotlin)
Android(Java)
import com.tencent.qcloud.tuicore.TUILogin
import com.tencent.qcloud.tuicore.interfaces.TUICallback
import com.tencent.qcloud.tuikit.tuicallkit.debug.GenerateTestUserSig

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)


val userId = "denny" // replace with your UserId
val sdkAppId = 0 // replace with the SDKAppID obtained on the console
val secretKey = "****" // replace with the SecretKey obtained on the console
val userSig = GenerateTestUserSig.genTestUserSig(userId, sdkAppId, secretKey)
TUILogin.login(this, sdkAppId, userId, userSig, object : TUICallback() {
override fun onSuccess() {
}
override fun onError(errorCode: Int, errorMessage: String) {
}
})
}
}
import com.tencent.qcloud.tuicore.TUILogin;
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
import com.tencent.qcloud.tuikit.tuicallkit.debug.GenerateTestUserSig;

public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String userId = "denny"; // replace with your UserId
int sdkAppId = 0; // replace with the SDKAppID obtained in step 1 on the console
String secretKey = "****"; // replace with the SecretKey obtained in step 1 on the console
String userSig = GenerateTestUserSig.genTestUserSig(userId, sdkAppId, secretKey);
TUILogin.login(this, sdkAppId, userId, userSig, new TUICallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(int errorCode, String errorMessage) {
}
});
}
}

Parameter
Type
Description
userId
String
Only allowing a combination of uppercase and lowercase letters (a-z A-Z), numbers (0-9), hyphens, and underscores.
sdkAppId
int
The unique identifier SDKAppID of the audio and video application created in the Tencent RTC console.
secretKey
String
The SDKSecretKey of the audio/video application created in the Tencent RTC console.
userSig
String
A security protection signature used to authenticate user login, confirm whether the user is genuine, and prevent malicious attackers from misappropriating your cloud service usage rights.
Note:
Development environment: If you are in the local development and debugging stage, you can adopt the local GenerateTestUserSig.genTestSig function to generate userSig. In this method, the SDKSecretKey is very easy to decompile and reverse engineer. Once your key is leaked, attackers can steal your Tencent Cloud traffic.
Production environment: If your project is ready to launch, use server-side generation of UserSig.

Step 4.Set Nickname and Avatar [Optional]

The user logging in for the first time has no avatar and nickname information. You can set the avatar and nickname through the setSelfInfo API.
setSelfInfo
Android(Kotlin)
Android(Java)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit

val nickname = "jack"
val avatar = "https:/****/user_avatar.png"
TUICallKit.createInstance(context).setSelfInfo(nickname, avatar, null)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;

String nickname = "jack";
String avatar = "https:/****/user_avatar.png";
TUICallKit.createInstance(context).setSelfInfo(nickname, avatar, null);
Parameter
Type
Description
nickname
String
Target user's nickname
avatar
String
Target user's avatar

Step 5.Initiating a Call

The caller can initiate a voice or video call by calling the calls function and specifying the call type and the callee's userID. The calls API simultaneously supports one-to-one calls and group calls. When the userIDList contains a single userID, it is a one-to-one call; when the userIDList contains multiple userIDs, it is a group call.
calls
Kotlin
Java
import com.tencent.cloud.tuikit.engine.call.TUICallDefine
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit

val userIdList = mutableListOf<String>()
userIdList.add("mike")
val mediaType = TUICallDefine.MediaType.Audio
val params = TUICallDefine.CallParams()
TUICallKit.createInstance(context).calls(userIdList, mediaType, params, null)
import com.tencent.qcloud.tuikit.tuicallengine.TUICallDefine;
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;

List<String> userIdList = new ArrayList<>();
userIdList.add("mike");
TUICallDefine.MediaType mediaType = TUICallDefine.MediaType.Audio;
TUICallDefine.CallParams params = new TUICallDefine.CallParams();
TUICallKit.createInstance(context).calls(userIdList, mediaType, params, null);
Parameter
Type
Description
userIdList
List<String>
Target user ID list
mediaType
Media type of the call, such as video call, voice call
params
Call extension parameters, such as room number, call invitation timeout, offline push custom content

Step 6.Answering a Call

After the recipient completes login, the caller can initiate a call, and the recipient will receive the call invitation with ringtone and vibration.

More Features

Enabling Floating Window

You can enable/disable the floating window feature by calling enableFloatWindow. Enable this feature when initializing the TUICallKit component, with the default status being Off (false). Click the floating window button in the top-left corner of the call interface to minimize the call interface into a floating window format.

enableFloatWindow
Kotlin
Java
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit

TUICallKit.createInstance(this).enableFloatWindow(true)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;

TUICallKit.createInstance(this).enableFloatWindow(true);
Details: Default false, the floating window button in the top-left corner of the call interface is hidden. Set to true to display.

Enabling Banner

You can turn on/off the incoming call banner display by calling enableIncomingBanner. This feature is disabled by default (false). When the callee receives an inbound call, the full-screen call waiting interface is displayed by default. After enabling this feature, a banner notification will be displayed first, then switch to the full-screen call view as needed. Please note that displaying the incoming call banner requires granting the floating permission. The specific display policy depends on the permission setting and whether the app is running in the foreground or background operation. For specific policies, refer to: incoming call display policy for the callee.

enbalecomingBanner
Android(Kotlin)
Android(Java)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit

TUICallKit.createInstance(context).enableIncomingBanner(true)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;

TUICallKit.createInstance(context).enableIncomingBanner(true);
Details: Default false. The callee side pops up the full-screen call waiting interface by default when receiving an invitation. When enabled, a banner is displayed first, then the full-screen call interface is pulled up as needed.

Ringtone Setting

You can set the default ringtone, incoming call silent mode, and Offline Push Ringtone in the following ways:
Method 1: If you depend on TUICallKit component via source code, you can replace the resource file (ringtone when initiating a call, ringtone when receiving a call) to set default ringtone
Method 2: Use the setCallingBell interface to set the incoming call ringtone received by the callee.
setCallingBell
Android(Kotlin)
Android(Java)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit

val filePath = "***/callingBell.mp3"
TUICallKit.createInstance(context).setCallingBell(filePath)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;

String filePath = "***/callingBell.mp3";
TUICallKit.createInstance(context).setCallingBell(filePath);
Details: Only local file paths can be imported here. Ensure the file directory is accessible to the app. The ringtone setting is bound to the device. Replacing the user will not affect the ringtone. To restore the default ringtone, just pass an empty filePath.
Parameter
Type
Description
filePath
String
ringtone file path
Incoming call silent mode: You can set mute mode through enableMuteMode.
enableMuteMode
Android(Kotlin)
Android(Java)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit

TUICallKit.createInstance(context).enableMuteMode(true)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;

TUICallKit.createInstance(context).enableMuteMode(true);
Details: When turned on, incoming call requests will not trigger ringtone playback.
Custom offline push ringtone: see custom ringtone.

Customizing Your UI

Replacing Icon Button

You can directly replace the icons under the res\drawable-xxhdpi folder to ensure the icon color and style remain consistent throughout the entire App. The following list shows basic feature buttons. You can replace the corresponding icons to fit your own business scenario.

Hidden Button

Call the disableControlButton API to hide specific buttons. For example, the hiding of the camera button:
disableControlButton
Android(Kotlin)
Android(Java)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit
import com.tencent.qcloud.tuikit.tuicallkit.common.data.Constants

TUICallKit.createInstance(context).disableControlButton(Constants.ControlButton.Camera)
import com.tencent.qcloud.tuikit.tuicallkit.TUICallKit;
import com.tencent.qcloud.tuikit.tuicallkit.common.data.Constants;

TUICallKit.createInstance(context).disableControlButton(Constants.ControlButton.Camera);
Parameter
Type
Description
disableButton
ControlButton
Button to hide.
Note:
Currently supports hiding the following buttons:
Camera, Microphone, Audio Device, Switch Camera, Invite User
v3.2.+ Version support.

FAQs

If you encounter any issues during integration and use, please refer to Frequently Asked Questions.

Contact Us

If you have any suggestions or feedback, please contact info_rtc@tencent.com.