UI Kit quickstart
The fastest and easiest way to get started with Agora Video Calling is to use the UI Kit. It implements commonly-used features and flows to get you up and running in minutes. This open source project includes best practices for business logic, as well as a pre-built UI that is highly customizable.
This page outlines the minimum code you need to integrate high-quality, low-latency Video Calling functionality into your app using the UI Kit.
Understand the tech
UI Kit simplifies the implementation of Video Calling by handling common calling logic such as remote user status, and displaying it in a pre-built customizable UI. UI Kit contains the following components:
To use the UI Kit, implement the following steps in your app:
-
Create an instance of the viewer
Declare and initialize an instance of the UI Kit viewer.
-
Join a channel
When you execute the
join
command, your app joins the channel, publishes the local audio and video streams to Agora SD-RTN™, and handles audio and video for anyone else who joins the call in a default UI.Yes, you read that right. After initializing a viewer instance, you can create or join a channel with just one line of code.
Prerequisites
To follow this procedure you must have:
- Android Studio 4.2 or higher.
- Android SDK API Level 21 or higher.
- Two mobile devices running Android 5.0 or higher.
- A computer with Internet access. If a firewall is deployed in your network environment, refer to Connect through restricted networks with Cloud Proxy to use Agora services normally.
- A camera and a microphone
- A valid Agora account and project
Project setup
To integrate Video Calling into your app using UI Kit, do the following:
-
In Android Studio, create a new Phone and Tablet Android project with an Empty Activity using Java. Set Minimum SDK to API 24.
After creating the project, Android Studio automatically starts gradle sync. Ensure that the sync succeeds before you continue.
-
Integrate UI Kit into your project:
In
Gradle Scripts/settings.gradle (Project Settings)
, reference thejitpack
repository by adding the following line to therepositories
section insidedependencyResolutionManagement
: -
In
Gradle Scripts/build.gradle (Module: <projectname>)
, add the UI Kit dependency. Thedependencies
section should look like the following:Find the Latest version of the UI Kit and replace
<version>
with the one you want to use. For example: 4.0.1. -
Sync Gradle and import the UI Kit.
-
Add permissions for network and device access.
In
/app/Manifests/AndroidManifest.xml
, add the following permissions after</application>
:
Implement a client for Video Calling
When a user opens the app, you initialize UI Kit. When the user taps a button, the app joins or leaves a channel. When another user joins the same channel, their video and audio is rendered in the app. This simple workflow enables you to concentrate on implementing Agora features and not UX bells and whistles.
To integrate real-time video with a ready-made user interface into your app using UI Kit:
Import the UI Kit classes
In /app/java/com.example.<projectname>/MainActivity
, add the provided code sample after import android.os.Bundle;
:
Add the variables to initiate and join a channel
In /app/java/com.example.<projectname>/MainActivity
, add the provided code sample after AppCompatActivity
:
Create a function that initializes an AgoraVideoViewer
instance and joins a channel
In /app/java/com.example.<projectname>/MainActivity
, add the provided code sample after the variable declarations:
Start your app
In /app/java/com.example.<projectname>/MainActivity
, update onCreate
to run initializeAndJoinChannel()
when the app starts. The updated code should like the provided code sample:
Test your implementation
To ensure that you have implemented Video Calling in your app:
-
Generate a temporary token in Agora Console
-
In your browser, navigate to the Agora web demo and update App ID, Channel, and Token with the values for your temporary token, then click Join.
-
In Android Studio, in
app/java/com.example.<projectname>/MainActivity
, updateappId
,channelName
andtoken
with the values for your temporary token. -
Connect a physical Android device to your development device.
-
In Android Studio, click Run app. A moment later you see the project installed on your device.
-
If this is the first time you run the project, grant microphone and camera access to your app, then press the button to join a channel.
- Now, you can see yourself and the remote user on the test device and talk to the remote user using your app.
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
To implement token authentication when using the UI Kit, refer to the following steps:
Authentication using UI Kit
-
Specify the token server URL
In the
MainActivity
class, declare the following variable to hold the token server URL.Make sure you specify the token-server URL in exactly the same format as shown in the example.
-
Set the token URL for AgoraVideoViewer
To set the token URL, you create an
AgoraSettings
object, set itsTokenURL
property and pass this object to the constructor when initializingAgoraVideoViewer
. To do this, replace the code in thetry {…}
block of theinitializeAndJoinChannel()
method with the following: -
Fetch a token from the server when you join a channel
In the
joinChannel()
method, replace theagView.join
call with the following:
See also
- Now you have created an app with UI Kit, see how to Customize your app.
-
See the Open Source UI Kit projects on GitHub here.
-
Downloads shows you how to install Video SDK manually.
-
To ensure communication security in a test or production environment, use a token server to generate token is recommended to ensure communication security, see Implement the authentication workflow.
Since UI Kit is a drop-in solution, it has customization limits that might not meet all your needs. If you want to change the UI or add more features, fork the open-source GitHub repository and build your own version. For substantially different scenarios and UI implementations, implement your own solution by following the SDK Quickstart guide.