You can download and install the app we provide to try out the real-time audio/video call feature.
Call | Answer |
---|---|
Note:To make it easier for you to implement the real-time audio/video call feature, we have refactored the
TUICalling
component. You no longer need to pay attention to UI as it is now implemented within theTUICalling
component.
TestVideoCall
and click Create.Note:This feature uses two basic PaaS services of Tencent Cloud, namely TRTC and IM. When you activate TRTC, IM will be activated automatically. IM is a value-added service. See Value-added Service Pricing for its billing details.
Clone or download the TUICalling source code.
In the Modify Configuration step, select your platform.
Find and open Android/Debug/src/main/java/com/tencent/liteav/debug/GenerateTestUserSig.java
.
Set parameters in GenerateTestUserSig.java
:
Click Next to complete the creation.
After compilation, click Return to Overview Page.
Note:
- The method for generating
UserSig
described in this document involves configuringSECRETKEY
in client code. In this method,SECRETKEY
may be easily decompiled and reversed, and if your key is disclosed, attackers can steal your Tencent Cloud traffic. Therefore, this method is suitable only for the local execution and debugging of the app.- The correct
UserSig
distribution method is to integrate the calculation code ofUserSig
into your server and provide an application-oriented API. WhenUserSig
is needed, your application can send a request to the business server for a dynamicUserSig
. For more information, see How do I calculate UserSig on the server?.
Open the source code project TUICalling
with Android Studio (version 3.5 or above) and click Run.
Note:You need at least two devices to try out the application.
Enter a username (which must be unique) and log in.
Enter the userId
of the person you want to call and tap Search.
Tap Call and select Video Call (Make sure that the callee is active in the application, or the call may fail).
Enter a username (which must be unique) and log in.
Go to the homepage and wait for the incoming call.
In the source code, the Source
folder contains two subfolders: ui
and model
. The model
subfolder includes the open-source TUICallingManager
component, which we share with the public. You can find the component’s APIs in the TUICalling.java
file.
You can enable the real-time audio/video call feature for your project with ease using the open-source TUICalling
and TUICallingManager
components, with no need to implement complicated call UI or logic by yourself.
The audio/video call component TUICalling
depends on the TRTC SDK and IM SDK. Follow the steps below to integrate the two SDKs into your project:
Add the TRTC SDK and IM SDK dependencies to dependencies
.
dependencies {
compile "com.tencent.liteav:LiteAVSDK_TRTC:latest.release"
compile 'com.tencent.imsdk:imsdk:latest.release'
// As we use Gson for parsing, you also need to add the Google Gson dependency.
compile 'com.google.code.gson:gson:latest.release'
}
In defaultConfig
, specify the CPU architecture to be used by your application.
defaultConfig {
ndk {
abiFilters "armeabi-v7a"
}
}
Click Sync Now to sync the SDKs.
Note:If you have no problem connecting to mavenCentral, the SDKs will be downloaded and integrated into your project automatically.
If your access to the mavenCentral repository is slow, you can download the ZIP files of the SDKs and manually integrate them into your project as instructed in the documents below.
SDK | Download Page | Integration Guide |
---|---|---|
TRTC SDK | Download | Integration document |
IM SDK | Download | Integration documentation |
Configure permission requests for your application in AndroidManifest.xml
. The SDKs need the following permissions (on Android 6.0 and above, the camera and read storage permissions 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.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<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-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
In the proguard-rules.pro
file, add the SDK classes to the "do not obfuscate" list.
-keep class com.tencent.** { *;}
TUICalling
componentCopy the Source
directory to your project and import it in setting.gradle
as shown below:
include ':Source'
TUICallingManager.sharedInstance()
to initialize the component.TUILogin.init(context, SDKAppID, config, listener)
to initialize login.TUILogin.login(userId, userSig, callback)
to log in to the component. Specify the key parameters as described below:Parameter | Description |
---|---|
SDKAppID | You can view `SDKAppID` in the TRTC console. |
userId | ID of the current user, which is a string that can contain letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). We recommend you set it based on your business account system. |
userSig | Tencent Cloud's proprietary security signature. For the calculation method, please see UserSig. |
config | SDK configuration, which is used to set the log output level and log callback. You can pass `null` for this parameter. For details, see the sample code below. |
listener | IM listener, which is used to listen for some crucial callbacks, such as forced logout and `userSig` expiration. For details, see the sample code below. |
callback | Callback for login, which indicates whether login is successful. For details, see the sample code below. |
// Initialize the component
TUICallingManager manager = TUICallingManager.sharedInstance();
// Log in to the component
V2TIMSDKConfig config = new V2TIMSDKConfig();
config.setLogLevel(V2TIMSDKConfig.V2TIM_LOG_DEBUG);
config.setLogListener(new V2TIMLogListener() {
@Override
public void onLog(int logLevel, String logContent) {
}
});
TUILogin.init(this, ${Your `SDKAPPID`}, config, new V2TIMSDKListener() {
@Override
public void onKickedOffline() { // Callback for forced logout
mIsKickedOffline = true;
checkUserStatus();
}
@Override
public void onUserSigExpired() { // Callback for `userSig` expiration
mIsUserSigExpired = true;
checkUserStatus();
}
});
TUILogin.login("${Your `userId`}", "${Your `userSig`}", new V2TIMCallback() {
@Override
public void onError(int code, String msg) {
Log.d(TAG, "code: " + code + " msg:" + msg);
}
@Override
public void onSuccess() {
Log.d(TAG, "onSuccess");
}
});
call();
of TUICallingManager
to initiate a call, passing in the user IDs (userids
) and call type (type
). For the call type, you can pass in TUICalling.Type.AUDIO
(audio call) or TUICalling.Type.VIDEO
(video call). If only one user ID is passed in for userids
, the call is a one-to-one call; if two or more user IDs are passed in, the call is a group call.// 1. Initialize the component
TUICallingManager manager = TUICallingManager.sharedInstance();
// 2. Register the listener
manager.setCallingListener(new TUICalling.TUICallingListener() {
@Override
public boolean shouldShowOnCallView() {
return true;
}
@Override
public void onCallStart(String[] userIDs, TUICalling.Type type, TUICalling.Role role, final View tuiCallingView) {
if (!shouldShowOnCallView() || null == tuiCallingView) {
return;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
mCallingView = tuiCallingView;
addContentView(tuiCallingView, params);
}
});
}
@Override
public void onCallEnd(String[] userIDs, TUICalling.Type type, TUICalling.Role role, long totalTime) {
removeView();
}
@Override
public void onCallEvent(TUICalling.Event event, TUICalling.Type type, TUICalling.Role role, String message) {
if (TUICalling.Event.CALL_FAILED == event) {
removeView();
}
}
});
// 3. Make a call
manager.call(userIDs, TUICalling.Type.VIDEO);
Note:If your project does not require the offline answering feature, for example, if it offers online customer service, your integration can end at step 5. If your project is a social networking service, we recommend you enable offline answering.
The IM SDK supports offline push. However, since the offline push service of Android phones varies from vendor to vendor, the configuration required to enable offline push for Android is more complicated than that for iOS.
sendModel
) of TRTCCallingImpl
. After completing the offline push configuration for your application, you will be able to send notifications to offline users.The table below lists the APIs of the TUICalling
component.
API | Description |
---|---|
call | Sends call invitations by user ID. |
receiveAPNSCalled | Answers a call. |
setCallingListener | Sets the listener. |
setCallingBell | Sets the ringtone (preferably shorter than 30s). |
enableMuteMode | Enables/Disables the mute mode. |
enableCustomViewRoute | Enables/Disables custom views. After enabling custom views, you will receive a CallingView instance in the callback for calling/being called, and can decide how to display the view by yourself. The view must be displayed full screen or in proportion to the screen size; otherwise, an error may occur. |
Was this page helpful?