tencent cloud

Feedback

Last updated: 2024-06-24 15:25:26
    This article will introduce how to complete the integration of the TUIRoomKit Component in the shortest time. By following this document, you will complete the following key steps within ten minutes and ultimately obtain an audio/video conference function with a complete UI interface.
    Conference interface and partial function display
    
    
    

    Environment preparation

    Minimum compatibility with Android 4.4 (SDK API Level 19), recommended to use Android 5.0 (SDK API Level 21) and above.
    Android Studio 3.5 and above (Gradle 3.5.4 and above).
    Mobile devices with Android 4.4 and above.

    Step 1: Activate the service

    Before initiating a meeting with TUIRoomKit, you need to activate the exclusive multi-person audio and video interaction service for TUIRoomKit on the console. For specific steps, please refer to Activate Service.

    Step 2: Download the TUIRoomKit component

    1. Clone/download the code in Github, and then copy the timcommon and tuiroomkit subdirectories in the Android directory to the same level directory as the app in your current project.
    
    
    

    Step 3: Project configuration

    1. Find the setting.gradle (or settings.gradle.kts) file in the project root directory and add the following code to it. Its function is to import the tuiroomkit component into your current project.
    setting.gradle
    settings.gradle.kts
    include ':timcommon'
    include ':tuiroomkit'
    include (":timcommon") include (":tuiroomkit")
    2. Find the build.gradle (or build.gradle.kts) file in the app directory and add the following code to it. Its function is to declare the current app's dependence on the newly added tuiroomkit component.
    build.gradle
    build.gradle.kts
    api project(':tuiroomkit')
    api(project(":tuiroomkit"))
    3. Since we use the reflection feature of Java inside the SDK, we need to add some classes in the SDK to the unobfuscated list, so you need to add the following code to the proguard-rules.pro file:
    -keep class com.tencent.** { *; }
    4. Find the AndroidManifest.xml file in the app directory, and add tools:replace="android:allowBackup" to the application node to override the settings within the component and use your own settings.
    // app/src/main/AndroidManifest.xml
    <application android:name=".DemoApplication" android:allowBackup="false" android:icon="@drawable/app_ic_launcher" android:label="@string/app_name" android:largeHeap="true" android:theme="@style/AppTheme" tools:replace="android:allowBackup">

    Step 4: Login

    Add the following code to your project. Its function is to complete the component login by calling the relevant interface in TUILogin. This step is extremely critical, because you can only use the various functions of TUIRoomKit normally after logging in, so please be patient and check whether the relevant parameters are configured correctly:
    Java
    Kotlin
    import com.tencent.qcloud.tuicore.TUILogin; import com.tencent.qcloud.tuicore.interfaces.TUICallback;
    import com.tencent.cloud.tuikit.roomkit.debug.GenerateTestUserSig;
    
    String userId = "denny" // Please replace with your UserID
    int sdkAppId = 1400000001 // Please replace with the sdkAppId obtained in step one
    String sdkSecretKey = "xxxx" // Please replace with your sdkSecretKey
    String userSig = GenerateTestUserSig.genTestUserSig(sdkAppId, userId, sdkSecretKey);
    
    TUILogin.login(context,
    sdkAppId,
    userId,
    userSig,
    new TUICallback() {
    @Override
    public void onSuccess() {
    }
    @Override
    public void onError(int errorCode, String errorMessage) {
    }
    });
    import com.tencent.qcloud.tuicore.TUILogin import com.tencent.qcloud.tuicore.interfaces.TUICallback
    import com.tencent.cloud.tuikit.roomkit.debug.GenerateTestUserSig
    
    val userId = "denny" // Please replace with your UserID
    val sdkAppId = 1400000001 // Please replace with the sdkAppId obtained in step one
    val sdkSecretKey = "xxxx" // Please replace with your sdkSecretKey
    val userSig = GenerateTestUserSig.genTestUserSig(sdkAppId, userId, sdkSecretKey)
    
    TUILogin.login(this,
    sdkAppId,
    userId,
    userSig,
    object : TUICallback() {
    override fun onSuccess() {
    }
    
    override fun onError(errorCode: Int, errorMessage: String) {
    }
    })
    }
    TUILogin.login Parameter Description:
    Here is a detailed introduction to several key parameters needed in the login function:
    SDKAppID:Get it in the last step of activating the service.
    UserID:The ID of the current user, a string type, only allowed to contain English letters (a-z and A-Z), numbers (0-9), hyphens (-) and underscores (_).
    UserSig:Use the SDKSecretKey obtained in step 4 of activating the service to encrypt the SDKAppID, UserID and other information to obtain the UserSig, which is an authentication ticket used by Tencent Cloud to identify whether the current user can use TRTC services. You can generate a temporarily available UserSig through the auxiliary tools in the console.
    Note:
    Development environment:If you are in the local development and debugging stage, you can use the local GenerateTestUserSig.genTestUserSig() function to generate a userSig. The SDKSecretKey in this method can be easily decompiled and reverse-engineered. Once your key is leaked, attackers can steal your Tencent Cloud traffic.
    production environment:If your project is to be launched, please use the method of server-side generation of UserSig.

    Step 5: Start your first meeting

    1. Create a new activity_conference.xml file and add the interface layout(If there is no layout directory, please create a new one):
    <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/conference_container" android:layout_width="match_parent" android:layout_height="match_parent" />
    2. ConferenceMainFragment is the main interface of the conference. You only need to call quickStartConference to initiate a quick conference (passing in the custom room number in this function) and add ConferenceMainFragment to the current Activity in the quick conference callback onConferenceStarted to initiate a quick conference.
    Create a new ConferenceOwnerActivity.java file in the project.
    Java
    Kotlin
    import com.tencent.cloud.tuikit.roomkit.ConferenceError;
    import com.tencent.cloud.tuikit.roomkit.ConferenceMainFragment;
    import com.tencent.cloud.tuikit.roomkit.ConferenceObserver;
    
    public class ConferenceOwnerActivity extends AppCompatActivity {
    private ConferenceObserver mConferenceObserver;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);
    
    ConferenceMainFragment fragment = new ConferenceMainFragment();
    mConferenceObserver = new ConferenceObserver() {
    @Override
    public void onConferenceStarted(String conferenceId, ConferenceError error) {
    super.onConferenceStarted(conferenceId, error);
    if (error != ConferenceError.SUCCESS) {
    return;
    }
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.conference_container, fragment);
    transaction.commitAllowingStateLoss();
    }
    };
    fragment.setConferenceObserver(mConferenceObserver);
    // Replace "123456" with the corresponding conference number
    fragment.quickStartConference("123456");
    }
    }
    import com.tencent.cloud.tuikit.roomkit.ConferenceError
    import com.tencent.cloud.tuikit.roomkit.ConferenceMainFragment
    import com.tencent.cloud.tuikit.roomkit.ConferenceObserver
    
    class ConferenceOwnerActivity : AppCompatActivity() {
    private var mConferenceObserver : ConferenceObserver? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_conference)
    
    var fragment = ConferenceMainFragment()
    mConferenceObserver = object: ConferenceObserver() {
    override fun onConferenceStarted(conferenceId: String?, error: ConferenceError?) {
    super.onConferenceStarted(conferenceId, error)
    if (error != ConferenceError.SUCCESS) {
    return
    }
    val fragmentManager = supportFragmentManager
    val transaction = fragmentManager.beginTransaction()
    transaction.add(R.id.conference_container, fragment)
    transaction.commitAllowingStateLoss()
    }
    }
    fragment.setConferenceObserver(mConferenceObserver)
    // Replace "123456" with the corresponding conference number
    fragment.quickStartConference("123456")
    }
    }
    Register ConferenceOwnerActivity in the app/src/main/AndroidManifest.xml file.
    <!--app/src/main/AndroidManifest.xml -->
    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application ... <activity ... </activity>
    <!-- Add the following code to register ConferenceOwnerActivity --> <activity android:name=".ConferenceOwnerActivity" /> </application> </manifest>
    Note
    ConferenceOwnerActivity must inherit AppCompatActivity, otherwise the interface will not be displayed.
    ConferenceOwnerActivity must be registered in the AndroidManifest.xml file.
    3. After you call the TUILogin.login function, you can jumo to the ConferenceOwnerActivity conference interface based on your business. For example, the sample code for launching the conference interface in MainActivity.java of an empty project is as follows:
    Java
    Kotlin
    import android.content.Intent;
    import android.os.Bundle;
    import androidx.appcompat.app.AppCompatActivity;
    
    public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
    // Jump to ConferenceOwnerActivity Intent intent = new Intent(MainActivity.this, ConferenceOwnerActivity.class); startActivity(intent); } }
    import android.content.Intent
    import android.os.Bundle
    import androidx.appcompat.app.AppCompatActivity
    
    class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    // Jump to ConferenceOwnerActivity
    val intent = Intent(this, ConferenceOwnerActivity::class.java)
    startActivity(intent)
    }
    }

    Step 6: General members join the meeting

    1. ConferenceMainFragment is the main interface of the conference. You only need to call joinConference (passing in the room number you want to join in this function) to join the conference and add ConferenceMainFragment to the current Activity in the onConferenceJoined callback to join the conference to participate in the current conference.
    Create a new ConferenceGeneralActivity.java file in the project.
    Java
    Kotlin
    public class ConferenceGeneralActivity extends AppCompatActivity {
    private static final String TAG = "ConferenceGeneralActivity";
    
    private ConferenceObserver mConferenceObserver;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);
    
    ConferenceMainFragment fragment = new ConferenceMainFragment();
    mConferenceObserver = new ConferenceObserver() {
    @Override
    public void onConferenceJoined(String conferenceId, ConferenceError error) {
    super.onConferenceJoined(conferenceId, error);
    if (error != ConferenceError.SUCCESS) {
    Log.e(TAG, "Error : " + error);
    return;
    }
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.conference_container, fragment);
    transaction.commitAllowingStateLoss();
    }
    };
    fragment.setConferenceObserver(mConferenceObserver);
    // Replace "123456" with the corresponding conference number
    fragment.joinConference("123456");
    }
    }
    class ConferenceGeneralActivity : AppCompatActivity() { private val tag: String = "ConferenceGeneralActivity" private var mConferenceObserver : ConferenceObserver? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_conference) var fragment = ConferenceMainFragment() mConferenceObserver = object: ConferenceObserver() { override fun onConferenceJoined(conferenceId: String?, error: ConferenceError?) { super.onConferenceJoined(conferenceId, error) if (error != ConferenceError.SUCCESS) { Log.e(tag, "Error : $error") return } val fragmentManager = supportFragmentManager val transaction = fragmentManager.beginTransaction() transaction.add(R.id.conference_container, fragment) transaction.commitAllowingStateLoss() } } fragment.setConferenceObserver(mConferenceObserver) // Replace "123456" with the corresponding conference number fragment.joinConference("123456") } }
    Register ConferenceGeneralActivity in the app/src/main/AndroidManifest.xml file.
    <!--app/src/main/AndroidManifest.xml -->
    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application ... <activity ... </activity>
    <!-- Add the following code to register ConferenceOwnerActivity --> <activity android:name=".ConferenceOwnerActivity" />
    <!-- Add the following code to register ConferenceGeneralActivity -->
    <activity android:name=".ConferenceGeneralActivity" /> </application> </manifest>
    Note:
    ConferenceGeneralActivity must inherit AppCompatActivity, otherwise the interface will not be displayed.
    ConferenceGeneralActivity must be registered in the AndroidManifest.xml file.
    2. After you call the TUILogin.login function, you can jump to the ConferenceGeneralActivity conference interface where you need to join a conference. For example, the sample code for launching the conference interface in MainActivity.java of an empty project is as follows:
    Java
    Kotlin
    import android.content.Intent;
    import android.os.Bundle;
    import androidx.appcompat.app.AppCompatActivity;
    
    public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
    // Jump to ConferenceGeneralActivity Intent intent = new Intent(MainActivity.this, ConferenceGeneralActivity.class); startActivity(intent); } }
    import android.content.Intent
    import android.os.Bundle
    import androidx.appcompat.app.AppCompatActivity
    
    class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    // Jump to ConferenceGeneralActivity
    val intent = Intent(this, ConferenceGeneralActivity::class.java)
    startActivity(intent)
    }
    }

    Interface display

    When you successfully complete steps 1 - 6, the interface will appear as follows:
    Conference main interface
    User list
    
    
    
    
    
    

    Common problem

    If you encounter problems with access and use, please see the FAQ.

    Suggestions and Feedback

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

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support