tencent cloud

Feedback

Last updated: 2024-05-20 17:18:01

    Applicable Scenario

    TUIChat offers both private chat (1V1) and group chat (Group) features, supporting multiple operations on messages, such as sending different types of messages, long pressing a message to like/reply/quote, and querying message read receipt details.
    You can integrate TUIChat into your app alone. The chat interface has a wide range of usage scenarios, such as real estate agency consultation, online medical consultation, e-commerce online customer service, and remote loss assessment for insurance.
    The UI effect is as shown below:
    Minimalist
    RTL Language
    Classic
    Message Interface | Sending Multiple Types of Messages
    
    Message Like/Reply/Quote | Message Reply Details
    
    Message Read Receipt | Read Receipt Details
    
    Message Interface | Sending Multiple Types of Messages
    
    Message Like | Reply
    
    Message Read Receipt | Read Receipt Details
    
    Message Interface
    Sending multiple types of messages
    
    
    Message Like
    Reply
    
    
    Message Read Receipt
    Read Receipt Details
    
    

    Development Environment Requirements

    Android Studio-Giraffe
    Gradle-7.2
    Android Gradle Plugin Version-7.0.0
    kotlin-gradle-plugin-1.5.31

    Integrating TUIChat Source Code

    1. Download theSource Code from GitHub. Ensure the TUIKit folder is at the same level as your own project folder, for example:
    
    2. Add the TUIChat component in settings.gradle:
    // Include the internal communication module (required module)
    include ':tuicore'
    include ':tuicore'
    project(':tuicore').projectDir = new File(settingsDir, '../TUIKit/TUICore/tuicore')
    
    // Include the Chat component common module (required module)
    include ':timcommon'
    project(':timcommon').projectDir = new File(settingsDir, '../TUIKit/TIMCommon/timcommon')
    
    // Include the chat feature module (basic feature module)
    include ':tuichat'
    project(':tuichat').projectDir = new File(settingsDir, '../TUIKit/TUIChat/tuichat')
    3. Add TUIChat dependency in the App module:
    api project(':tuichat')
    4. 
    Add the maven repository and Kotlin support in the build.gradle file of the root project (at the same level as settings.gradle):
    
    buildscript {
    repositories {
    mavenCentral()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:7.0.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
    }
    }
    If you are using Gradle 8.x, you need to add the following code.
    buildscript {
    repositories {
    mavenCentral()
    maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:8.0.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0"
    }
    }

    Component Login

    The TUIChat component can be used normally only after logging in the chat feature successfully.
    The sdkAppID is required to be created and obtained from Chat console while the userSig needs to be calculated according to the rules. For detailed steps, refer to Get Started.
    The sample code is as follows:
    // Called when login is clicked on the user UI
    TUILogin.login(context, sdkAppID, userID, userSig, new TUICallback() {
    @Override
    public void onSuccess() {
    }
    @Override
    public void onError(final int code, final String desc) {
    }
    });

    Navigating to the Chat Window Activity

    You can pass in the chat information corresponding to the current chat interface, start Activity, and navigate to the chat interface.
    The sample code is as follows:
    Minimalist
    Classic
    Intent intent; if (isGroup) { intent = new Intent(this, TUIGroupChatMinimalistActivity.class); } else { intent = new Intent(this, TUIC2CChatMinimalistActivity.class); } // If it's a C2C chat, chatID is the other person's UserID; if it's a Group chat, chatID is the GroupID. intent.putExtra(TUIConstants.TUIChat.CHAT_ID, "chatID"); intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, isGroup ? V2TIMConversation.V2TIM_GROUP : V2TIMConversation.V2TIM_C2C); startActivity(intent);
    Intent intent; if (isGroup) { intent = new Intent(this, TUIGroupChatActivity.class); } else { intent = new Intent(this, TUIC2CChatActivity.class); } // If it's a C2C chat, chatID is the other person's UserID; if it's a Group chat, chatID is the GroupID. intent.putExtra(TUIConstants.TUIChat.CHAT_ID, "chatID"); intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, isGroup ? V2TIMConversation.V2TIM_GROUP : V2TIMConversation.V2TIM_C2C); startActivity(intent);

    Integrating the Chat Window into Your Own Activity

    You can also embed the TUIChat chat interface into your own Activity.
    The sample code is as follows:
    Minimalist
    Classic
    Fragment fragment;
    // If it's a C2C chat, chatID is the other person's UserID; if it's a Group chat, chatID is the GroupID.
    if (isGroup) { GroupInfo groupInfo = new GroupInfo(); groupInfo.setId(chatID); Bundle bundle = new Bundle(); bundle.putSerializable(TUIChatConstants.CHAT_INFO, groupInfo); TUIGroupChatMinimalistFragment tuiGroupChatFragment = new TUIGroupChatMinimalistFragment(); tuiGroupChatFragment.setArguments(bundle); GroupChatPresenter presenter = new GroupChatPresenter(); presenter.initListener(); tuiGroupChatFragment.setPresenter(presenter); fragment = tuiGroupChatFragment; } else { ChatInfo chatInfo = new ChatInfo(); chatInfo.setId(chatID); Bundle bundle = new Bundle(); bundle.putSerializable(TUIChatConstants.CHAT_INFO, chatInfo); TUIC2CChatMinimalistFragment tuic2CChatFragment = new TUIC2CChatMinimalistFragment(); tuic2CChatFragment.setArguments(bundle); C2CChatPresenter presenter = new C2CChatPresenter(); presenter.initListener(); tuic2CChatFragment.setPresenter(presenter); fragment = tuic2CChatFragment; }
    getSupportFragmentManager().beginTransaction() .add(R.id.chat_fragment_container, fragment).commitAllowingStateLoss();
    
    Fragment fragment;
    // If it's a C2C chat, chatID is the other person's UserID; if it's a Group chat, chatID is the GroupID.
    if (isGroup) { GroupInfo groupInfo = new GroupInfo(); groupInfo.setId(chatID); Bundle bundle = new Bundle(); bundle.putSerializable(TUIChatConstants.CHAT_INFO, groupInfo); TUIGroupChatFragment tuiGroupChatFragment = new TUIGroupChatFragment(); tuiGroupChatFragment.setArguments(bundle); GroupChatPresenter presenter = new GroupChatPresenter(); presenter.initListener(); tuiGroupChatFragment.setPresenter(presenter); fragment = tuiGroupChatFragment; } else { ChatInfo chatInfo = new ChatInfo(); chatInfo.setId(chatID); Bundle bundle = new Bundle(); bundle.putSerializable(TUIChatConstants.CHAT_INFO, chatInfo); TUIC2CChatFragment tuic2CChatFragment = new TUIC2CChatFragment(); tuic2CChatFragment.setArguments(bundle); C2CChatPresenter presenter = new C2CChatPresenter(); presenter.initListener(); tuic2CChatFragment.setPresenter(presenter); fragment = tuic2CChatFragment; }
    getSupportFragmentManager().beginTransaction() .add(R.id.chat_fragment_container, fragment).commitAllowingStateLoss();

    FAQs

    What should I do when I receive the message "Manifest merger failed: Attribute application@allowBackup value=(true) from AndroidManifest.xml"?
    In the Chat SDK, the default value of allowBackup is false, which indicates that the backup and restore features are disabled. You can delete allowBackup attribute from your AndroidManifest.xml file to indicate that the backup and restore features are disabled. You can also add tools:replace="android:allowBackup" in the application node of AndroidManifest.xml file to indicate overriding Char SDK settings and use your own settings.
    For example:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.tencent.qcloud.tuikit.myapplication">
    
    <application
    android:allowBackup="true"
    android:name=".MApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MyApplication"
    tools:replace="android:allowBackup">
    <activity android:name=".MainActivity">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>
    
    </manifest>
    What should I do when I receive the message "NDK at /Users//Library/Android/sdk/ndk-bundle did not have a source.properties file"?*
    Simply add your NDK path to the local.properties file, for example: ndk.dir=/Users/***/Library/Android/sdk/ndk/16.1.4479499
    What should I do when I receive the message "Cannot fit requested classes in a single dex file"?
    This issue might occur if your API level setting is too low. You need to enable MultiDex support in your App’s build.gradle file, by adding multiDexEnabled true and the corresponding dependency:
    android {
    defaultConfig {
    ...
    minSdkVersion 19
    targetSdkVersion 30
    multiDexEnabled true
    }
    ...
    }
    dependencies {
    implementation "androidx.multidex:multidex:2.0.1"
    }
    In addition, add the following code to the Application file:
    public class MyApplication extends SomeOtherApplication {
    @Override
    protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
    }
    }
    What should I do when I receive the message "Plugin with id 'kotlin-android' not found."?
    Since the TUIChat component uses the Kotlin code, you need to add a Kotlin build plug-in. Refer to step 4 of the "Integrating TUIChat Source Code" section above.
    Why does the App feature work normally in the Debug version but encounter issues in the Release version?
    This issue is very likely caused by aliasing. Try to avoid aliasing TUIKit. You can add the following aliasing rule:
    # Avoid deleting code logic -dontshrink -dontoptimize
    # Avoid aliasing TUIKit
    -keep class com.tencent.qcloud.** { *; }
    
    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