Seeking alternatives after Twilio video sunset?
Check our migration guide 
Only  $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Only $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Grab It Now 
Seeking alternatives after Twilio video sunset?
Check our migration guide 
Only  $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Only $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Grab It Now 
Menu

Android

Overview

Welcome to our comprehensive guide designed to assist developers in migrating from Twilio Video to Tencent RTC (TRTC) on the Android platform. This document provides a detailed comparison at the API level between Twilio and TRTC, and outlines each step required to implement basic RTC video functionality.
For those planning to develop a new application, you can directly visit the Tencent RTC website and documentation for all the necessary resources and information.

Create a TRTC Application

Create a new application of Tencent RTC (TRTC), then you can get the following necessary information for the authentication of TRTC service.

SDKAppID

SDKAppID is used to uniquely identify a TRTC application. It is generated automatically when an application is created.

SDKSecretKey

SDKSecretKey is one of the key parameter to be used to generate the security signature. The generated signature ensures the access of TRTC service when calling the initialization and login API of the SDK.

Install and Set Up the SDK

Environment Requirements

Android Studio 3.5 or later.
Android 4.1 (SDK API level 16) or later

Install the SDK

TRTC SDK has been released to the mavenCentral repository, and you can configure Gradle to download the SDK by the following steps,
1. Add the TRTC SDK dependency to dependencies.
dependencies { implementation 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release' }
2. In defaultConfig, specify the CPU architecture to be used by your application.
defaultConfig { ndk { abiFilters "armeabi-v7a", "arm64-v8a" } }
3. Click sync to download the SDK and integrate them into your project.

Project Configuration

Configure application permissions in AndroidManifest.xml. The TRTC SDK requires the following permissions.
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera.autofocus" />

Set Obfuscation Rules

In the file proguard-rules.pro, add the classes related to the TRTC SDK to the "do not obfuscate" list.
-keep class com.tencent.** { *;}

Join a Room

Twilio
// Join room val connectOptions = ConnectOptions.Builder(accessToken) .roomName(roomName) .audioTracks(localAudioTracks) .videoTracks(localVideoTracks) .dataTracks(localDataTracks) .build() val room = Video.connect(context, connectOptions, roomListener)
TRTC
//Initialize TRTC // Create trtc instance(singleton) and set up event listeners val mCloud = TRTCCloud.sharedInstance(getApplicationContext()); mCloud.setListener(this); // Join room // Please replace each field in TRTCParams with your own parameters val params = TRTCParams() params.sdkAppId = 1400000123 // Please replace with your own SDKAppID params.userId = "denny" // Please replace with your own userid params.roomId = 123321 // Please replace with your own room number params.userSig = "xxx" // Please replace with your own userSig params.role = TRTCCloudDef.TRTCRoleAnchor // If your application scenario is a video call between several people, please use "TRTC_APP_SCENE_LIVE" mCloud.enterRoom(params, TRTCCloudDef.TRTC_APP_SCENE_LIVE) // Listen for the `onEnterRoom` event of the SDK to get the room entry result // Listen for the `onEnterRoom` event of the SDK and learn whether the room is successfully entered @Override public void onEnterRoom(long result) { if (result > 0) { Log.d(TAG, "Enter room succeed"); } else { Log.d(TAG, "Enter room failed"); } }

Publish Local Video/Audio

Twilio
// Start video val cameraEnumerator = Camera2Enumerator(context) cameraEnumerator.deviceNames.firstOrNull { cameraEnumerator.isFrontFacing(it) }?.let { val cameraCapturer = Camera2Capturer(context, it) val localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer) cameraCapturer.startCapture(width, height, framerate) } // Stop video cameraCapturer.stopCapture()
TRTC
// Set the preview mode of the local video image: Enable horizontal mirroring and set the fill mode for the video image TRTCCloudDef.TRTCRenderParams param = new TRTCCloudDef.TRTCRenderParams(); param.fillMode = TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FILL; param.mirrorType = TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_AUTO; mCloud.setLocalRenderParams(param); // Enable local camera preview (`localCameraVideo` is the control used to render the local video image) TXCloudVideoView cameraVideo = findViewById(R.id.txcvv_main_local); mCloud.startLocalPreview(true, cameraVideo); // Use `TXDeviceManager` to enable autofocus and turn on the flash TXDeviceManager manager = mCloud.getDeviceManager(); if (manager.isAutoFocusEnabled()) { manager.enableCameraAutoFocus(true); } manager.enableCameraTorch(true); // Enable mic and set `quality` to `SPEECH` for the voice mode mCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH );

Subscribe Remote Video/Audio

Twilio
private lateinit var remoteVideoView: VideoView private fun setRoomListener() { remoteVideoView = findViewById(R.id.remote_video_view) val roomListener = object : Room.Listener { override fun onConnected(room: Room) { room.remoteParticipants.forEach { remoteParticipant -> addRemoteParticipant(remoteParticipant) } } override fun onParticipantConnected(room: Room, remoteParticipant: RemoteParticipant) { addRemoteParticipant(remoteParticipant) } } } private fun addRemoteParticipant(remoteParticipant: RemoteParticipant) { remoteParticipant.setListener(object : RemoteParticipant.Listener { override fun onVideoTrackSubscribed( remoteParticipant: RemoteParticipant, remoteVideoTrackPublication: RemoteVideoTrackPublication, remoteVideoTrack: RemoteVideoTrack ) { remoteVideoTrack.addSink(remoteVideoView) } override fun onVideoTrackUnsubscribed( remoteParticipant: RemoteParticipant, remoteVideoTrackPublication: RemoteVideoTrackPublication, remoteVideoTrack: RemoteVideoTrack ) { remoteVideoTrack.removeSink(remoteVideoView) } }) }
TRTC
// Play back the camera (primary stream) image of `denny` mCloud.startRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, cameraView);

Leave a Room

Twilio
room.disconnect()
TRTC
// Exit the current room mCloud.exitRoom(); // Listen for the `onExitRoom` callback to get the reason for room exit @Override public void onExitRoom(int reason) { if (reason == 0) { Log.d(TAG, "Exit current room by calling the 'exitRoom' api of sdk ..."); } else if (reason == 1) { Log.d(TAG, "Kicked out of the current room by server through the restful api..."); } else if (reason == 2) { Log.d(TAG, "Current room is dissolved by server through the restful api..."); } }

Conclusion

Compared to Twilio Video, this migration guide outlines how to use Tencent RTC (TRTC) to build a basic video RTC experience for the Android platform. The API level "mapping" for each step in this guide will facilitate the developers to switch from Twilio Video to TRTC in a quick and straightforward way.
TRTC has more feature sets that can help developers implement cost-effective, low-latency and high-quality interactive audio/video services. For comprehensive details on TRTC features and the implementation specification, please refer to the Tencent RTC website. If you require developer support or any further assistance regarding the TRTC integration, feel free to contact us, or you can join our Discord and Telegram. We will ensure a smooth integration and address any queries you may have.