tencent cloud

Tencent Real-Time Communication

Release Notes and Announcements
Release Notes
Recent Product Announcement
TRTC Live (TUILiveKit) Product Launch Announcement
TRTC Conference Official Editions Launched
The commercial version of Conference is coming soon
Terms and Conditions Applicable to $9.9 Starter Package
Rules for the "First Subscription $100 Discount" Promotion
Announcement on the Start of Beta Testing for Multi-person Audio and Video Conference
TRTC Call Official Editions Launched
License Required for Video Playback in New Version of LiteAV SDK
TRTC to Offer Monthly Packages
Product Introduction
Overview
Concepts
Features
Strengths
Use Cases
Performance Statistics
Tencent RTC Quickplay: Experience Ultimate Real-Time Audio and Video Interaction!
Purchase Guide
Billing Overview
Free Minutes
Monthly subscription
Pay-as-you-go
TRTC Overdue and Suspension Policy
FAQs
Refund Instructions
User Tutorial
Free Demo
Call
Overview
Activate the Service
Run Demo
Integration
Offline Call Push
Conversational Chat
On-Cloud Recording
AI Noise Reduction
UI Customization
Calls integration to Chat
Additional Features
No UI Integration
Server APIs
Client APIs
Solution
ErrorCode
Release Notes
FAQs
Conference
Overview(TUIRoomKit)
Activate the Service (TUIRoomKit)
Run Demo(TUIRoomKit)
Integration(TUIRoomKit)
Screen Sharing (TUIRoomKit)
Schedule a meeting (TUIRoomKit)
In-meeting Call (TUIRoomKit)
UI Customization(TUIRoomKit)
Virtual Background (TUIRoomKit)
Conference Control (TUIRoomKit)
Cloud Recording (TUIRoomKit)
AI Noise Reduction (TUIRoomKit)
In-Conference Chat (TUIRoomKit)
Robot Streaming (TUIRoomKit)
Enhanced Features (TUIRoomKit)
Client APIs (TUIRoomKit)
Server APIs (TUIRoomKit)
FAQs (TUIRoomKit)
Error Code (TUIRoomKit)
SDK Update Log (TUIRoomKit)
Live
Billing of Video Live Component
Overview
Activating the Service (TUILiveKit)
Run Demo
No UI Integration
UI Customization
Live Broadcast Monitoring
Video Live Streaming
Voice Chat Room
Advanced Features
Client APIs
Server APIs
Error Codes
Release Notes
FAQs
RTC Engine
Activate Service
SDK Download
API Examples
Usage Guidelines
API Reference Manual
Advanced Features
AI Integration
Overview
Configure MCP Server
Install Skills
Integration Guide
FAQ
RTC RESTFUL API
History
Introduction
API Category
Room Management APIs
Stream mixing and relay APIs
On-cloud recording APIs
Data Monitoring APIs
Pull stream Relay Related interface
Web Record APIs
AI Service APIs
Cloud Slicing APIs
Cloud Moderation APIs
Making API Requests
Call Quality Monitoring APIs
Usage Statistics APIs
Data Types
Appendix
Error Codes
Console Guide
Application Management
Package Management
Usage Statistics
Monitoring Dashboard
Development Assistance
Solution
Real-Time Chorus
FAQs
Migration Guide
Billing
Features
UserSig
Firewall Restrictions
How to Downsize Installation Package
Android and iOS
Web
Flutter
Electron
TRTCCalling for Web
Audio and Video Quality
Others
Legacy Documentation
RTC RoomEngine SDK(Old)
Integrating TUIRoom (Web)
Integrating TUIRoom (Android)
Integrating TUIRoom (iOS)
Integrating TUIRoom (Flutter)
Integrating TUIRoom (Electron)
TUIRoom APIs
On-Cloud Recording and Playback (Old)
RTC Analytics Monthly Packages (Previous Version)
Protocols and Policies
Compliance
Security White Paper
Notes on Information Security
Service Level Agreement
Apple Privacy Policy: PrivacyInfo.xcprivacy
TRTC Policy
Privacy Policy
Data Processing And Security Agreement
Glossary

Integrating TUIRoom (Android)

PDF
Focus Mode
Font Size
Last updated: 2024-09-14 16:38:21

Overview

TUIRoom is an open-source UI component for audio/video communication. With just a few lines of code changes, you can integrate it into your project to implement screen sharing, beauty filters, low-latency video calls, and other features. In addition to the Android component, we also offer components for iOS, Windows, macOS, and more.
Note
All components of TUIKit use Tencent Cloud's TRTC and Chat services. When you activate TRTC, Chat and the trial edition of the Chat SDK (which supports up to 100 DAUs) will also be activated automatically. For Chat billing details, see Pricing.





Integration

Step 1. Download and import the TUIRoom component

Go to the component's GitHub page, clone or download the code, and copy the tuiroom and debug, and tuibeauty folders in the Android directory to your project. Then, do the following to import the component:
1. Add the code below in setting.gradle:
include ':tuiroom'
include ':debug'
include ':tuibeauty'
2. Add dependencies on tuiroom, debug, and tuibeauty to the build.gradle file in app:
api project(':tuiroom')
api project(':debug')
api project(':tuibeauty')
3. Add the TRTC SDK (liteavSdk) and Chat SDK (imsdk) dependencies in build.gradle in the root directory:
ext {
liteavSdk = "com.tencent.liteav:LiteAVSDK_TRTC:latest.release"
imSdk = "com.tencent.imsdk:imsdk-plus:latest.release"
}

Step 2. Configure permission requests and obfuscation rules

1. Configure permission requests for your app in AndroidManifest.xml. The SDKs need the following permissions (on Android 6.0 and later, the mic permission must be requested at runtime.)
<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.CAMERA" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
2. In the proguard-rules.pro file, add the SDK classes to the "do not obfuscate" list.
-keep class com.tencent.** { *;}

Step 3. Create and initialize an instance of the component

// 1. Log in to the component
TUILogin.addLoginListener(new TUILoginListener() {
@Override
public void onKickedOffline() { // Callback for forced logout (for example, due to login from another device)
}

@Override
public void onUserSigExpired() { // Callback for `userSig` expiration
}
});

TUILogin.login(context, "Your SDKAppId", "Your userId", "Your userSig", null);


// 2. Initialize the `TUIRoom` instance
TUIRoom tuiRoom = TUIRoom.sharedInstance(this);

Parameter description

SDKAppID: TRTC application ID. If you haven't activated TRTC, log in to the TRTC console, create a TRTC application, click Application Info, and select the Quick Start tab to view its SDKAppID.


Secretkey: TRTC application key. Each secret key corresponds to a SDKAppID. You can view your application’s secret key on the Application Management page of the TRTC console.
userId: ID of the current user, which is a string that can contain only letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). We recommend that you keep it consistent with your user account system.
UserSig: Security signature calculated based on SDKAppID, userId, and Secretkey. You can click here to quickly generate a UserSig for testing. For more information, see UserSig.

Step 4. Implement group audio/video communication

1. Create a room
tuiRoom.createRoom(12345, TUIRoomCoreDef.SpeechMode.FREE_SPEECH, true, true);
2. Join a room
tuiRoom.enterRoom(12345, true, true);

Step 5. Implement room management (optional)

1. The room owner calls TUIRoomCore#destroyRoom to close the room.
// 1. The room owner calls the API below to close the room.
mTUIRoomCore.destroyRoom(new TUIRoomCoreCallback.ActionCallback() {
@Override
public void onCallback(int code, String msg) {

}
});

Other users in the room will receive the `onDestroyRoom` callback.
@Override
public void onDestroyRoom() {
// The room owner closes and exits the room.
}
2. A user in the room calls TUIRoomCore#leaveRoom to leave the room.
// 1. A user (not the room owner) calls the API below to leave the room.
mTUIRoomCore.leaveRoom(new TUIRoomCoreCallback.ActionCallback() {
@Override
public void onCallback(int code, String msg) {

}
});

Other users in the room will receive the `onRemoteUserLeave` callback.
@Override
public void onRemoteUserLeave(String userId) {
Log.d(TAG, "onRemoteUserLeave userId: " + userId);
}

Step 6. Implement screen sharing (optional)

Call TUIRoomCore#startScreenCapture to implement screen sharing.
// 1. Add the SDK’s screen sharing activity and permission in `AndroidManifest.xml`
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application>
<activity
android:name="com.tencent.rtmp.video.TXScreenCapture$TXScreenCaptureAssistantActivity"
android:theme="@android:style/Theme.Translucent" />
</application>

// 2. Request the floating window permission in your UI
if (Build.VERSION.SDK_INT >= 23) {
if (!Settings.canDrawOverlays(getApplicationContext())) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 100);
} else {
startScreenCapture();
}
} else {
startScreenCapture();
}

// 3. System callback result
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 100) {
if (Build.VERSION.SDK_INT >= 23) {
if (Settings.canDrawOverlays(this)) {
// The user grants the permission.
startScreenCapture();
} else {
}
}
}
}

// 4. Start screen sharing
private void startScreenCapture() {
TRTCCloudDef.TRTCVideoEncParam encParams = new TRTCCloudDef.TRTCVideoEncParam();
encParams.videoResolution = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_1280_720;
encParams.videoResolutionMode = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAIT;
encParams.videoFps = 10;
encParams.enableAdjustRes = false;
encParams.videoBitrate = 1200;

TRTCCloudDef.TRTCScreenShareParams params = new TRTCCloudDef.TRTCScreenShareParams();
mTUIRoom.stopCameraPreview();
mTUIRoom.startScreenCapture(encParams, params);
}

Suggestions and Feedback

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

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback