Back to Blog

Migration Guide from Twilio to Agora: Android Edition

Migration Guide from Twilio to Agora: Android Edition

We're offering up to 2 free months to any customer switching from Twilio video to Agora. Schedule some time to chat with our team to get the full details.


Introduction

This guide will assist you in migrating your existing Twilio Video implementation to the Agora Video SDK. If you are initiating a new project, it is advised to refer to the Agora Video SDK documentation.

Quickstart

Quickstart demos for Android are provided. Check them out at Quickstart Demo. Additional demos can be found at More Demos.

Please follow the documentation here: Video Calling SDK quickstart - Android.

Creating an Account with Agora

Sign up for an account and log in to the Agora Console.

Agora React SDK: Build a video conferencing app in minutes - Signup
The project management tab on the Agora website

Navigate to the Project List tab under the Project Management tab, and create a project by clicking the blue Create button. (When prompted to use App ID + Certificate, select App ID only.) Retrieve the App ID, which will be used to authorize your requests while you’re developing the application.

Note: This guide does not implement token authentication, which is recommended for all RTE apps running in production environments. For more information about token-based authentication in the Agora platform, see this guide: https://docs.agora.io/en/video-calling/get-started/authentication-workflow?platform=android

Step 1: Obtain Agora Video SDK Keys

To access Agora services and integrate them into your project, follow these steps to obtain the necessary information from the Agora Console:

  1. App ID:
    • Log in to the Agora Console and navigate to your project.
    • Find the “App ID,” a randomly generated string unique to your App. This ID is crucial for identifying your application within Agora.
  2. Temporary Token:
    • When clients from your App join a channel, they need a Token for authentication.
    • Generate a temporary Token from the Agora Console, which has a validity period of 24 hours. This Token is used to authenticate users joining your channel.
  3. Channel Name
    • Define a unique string as the “Channel Name” to identify and label your channel.

By completing these steps, you'll have the necessary credentials to integrate Agora services into your application. Refer to the Agora Console for detailed guidance on accessing and managing these credentials.

Step 2: Install Agora Video SDK

Install

Through the Maven Central repository. Add this line to your app/build.gradle file:

implementation 'io.agora.rtc:full-sdk:<version>'
view raw build.gradle hosted with ❤ by GitHub

Remove Twilio SDK from your project

Remove this line in app/build.gradle file:

implementation 'com.twilio:video-android:<version>'
view raw build.gradle hosted with ❤ by GitHub

Set permissions

Ensure that you have all of the Android system permissions required by the Video SDK in your project (you can ignore permissions that you already have):

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- The Agora SDK requires Bluetooth permissions in case users are using Bluetooth devices. -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- For Android 12 and above devices, the following permission is also required. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

If your project uses proguard, add the following rules to your project.

-keep class io.agora.**{*;}

Step 3: Start and Join Sessions

Twilio

// Join room
val connectOptions = ConnectOptions.Builder(joinToken)
.videoTracks(localVideoTracks)
.audioTracks(localAudioTracks)
.roomName(sessionId)
.build()
Video.connect(context, connectOptions, roomListener)
view raw main.kt hosted with ❤ by GitHub

Agora

// Initialize Agora Client
try {
// Set the engine configuration
val config = RtcEngineConfig()
config.mContext = mContext
config.mAppId = appId
// Assign an event handler to receive engine callbacks
config.mEventHandler = iRtcEngineEventHandler
// Create an RtcEngine instance
agoraEngine = RtcEngine.create(config)
// By default, the video module is disabled, call enableVideo to enable it.
agoraEngine!!.enableVideo()
} catch (e: Exception) {
sendMessage(e.toString())
return false
}
// Join room
val options = ChannelMediaOptions()
options.channelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER
agoraEngine!!.joinChannel(token, channelName, localUid, options)
view raw main.kt hosted with ❤ by GitHub

Step 4: Video controls and Render Local User Video

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)
}
// Render local user video
val previewVideoView = VideoView(context)
localVideoTrack?.addSink(previewVideoView)
// Stop video
cameraCapturer.stopCapture()
view raw main.kt hosted with ❤ by GitHub

Agora

// Start video
agoraEngine!!.startPreview()
// Render local user video
val localSurfaceView = SurfaceView(mContext)
agoraEngine!!.setupLocalVideo(
VideoCanvas(
localSurfaceView,
VideoCanvas.RENDER_MODE_HIDDEN,
0
)
)
// Stop video
agoraEngine!!.stopPreview()
view raw main.kt hosted with ❤ by GitHub

Step 5: Render Remote User Video

Twilio

val remoteVideoView = VideoView(context)
remoteVideoTrack.addSink(remoteVideoView)
remoteVideoTrack.removeSink(remoteVideoView)
view raw main.kt hosted with ❤ by GitHub

Agora

val remoteSurfaceView = SurfaceView(mContext)
remoteSurfaceView.setZOrderMediaOverlay(true)
// Create a VideoCanvas using the remoteSurfaceView
val videoCanvas = VideoCanvas(
remoteSurfaceView,
VideoCanvas.RENDER_MODE_FIT, remoteUid
)
agoraEngine!!.setupRemoteVideo(videoCanvas)
view raw main.kt hosted with ❤ by GitHub

Step 6: Audio Controller

Twilio

audioTrack.enable(enable)
view raw main.kt hosted with ❤ by GitHub

Agora

agoraEngine!!.enableLocalAudio(enable)
view raw main.kt hosted with ❤ by GitHub

Step 7: Leave and End Sessions

Twilio

room.disconnect()
view raw main.kt hosted with ❤ by GitHub

Agora

agoraEngine!!.leaveChannel()
view raw main.kt hosted with ❤ by GitHub

Additional Agora Video SDK Features

The Agora Video SDK provides a rich set of features that can enhance your video conferencing application. Here are some key features and information to consider:

  1. Platform Support:
    Agora Video SDK supports a variety of platforms, including Android, iOS, Web, Linux, macOS, and Windows. Additionally, it offers wrappers for popular frameworks like Flutter and React Native.
  2. Cloud Recording:
    Agora Video SDK provides cloud recording capabilities, allowing you to capture and store your sessions for later playback or archival purposes. Consult the Agora Video SDK documentation for details on implementing this feature.
  3. Screen Sharing:
    Implement screen sharing in your application using Agora’s screen-sharing capabilities. This feature is valuable for collaborative work and presentations.
  4. Plug-in Architecture:
    Agora’s support for plug-ins enhances the extensibility of your video application. You can seamlessly integrate additional functionalities or customize features by leveraging Agora’s plug-in architecture.
  5. Tree-Shaking:
    Agora Video SDK supports tree-shaking, enabling you to optimize your application’s bundle size by eliminating unused code during the build process. This ensures that your application remains lightweight and performs efficiently.
  6. Secure Communication:
    Agora’s end-to-end encryption ensures that the communication between users in a session is highly secure. This feature enhances privacy and protects sensitive information exchanged during video conferences.

For comprehensive details on Agora Video SDK features and how to implement them, refer to the Agora Video SDK Documentation.

Explore the full potential of Agora Video SDK to create a robust and feature-rich video conferencing experience. If you have specific feature requirements, consult the documentation for guidance on implementation.

RTE Telehealth 2023
Join us for RTE Telehealth - a virtual webinar where we’ll explore how AI and AR/VR technologies are shaping the future of healthcare delivery.

Learn more about Agora's video and voice solutions

Ready to chat through your real-time video and voice needs? We're here to help! Current Twilio customers get up to 2 months FREE.

Complete the form, and one of our experts will be in touch.

Try Agora for Free

Sign up and start building! You don’t pay until you scale.
Try for Free