// Include the upper-layer app moduleinclude ':app'// Include the internal communication module (required module)include ':tuicore'project(':tuicore').projectDir = new File(settingsDir, '../TUIKit/TUICore/tuicore')// Include the common module of IM component (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')// Include the relationship chain feature module (basic feature module)include ':tuicontact'project(':tuicontact').projectDir = new File(settingsDir, '../TUIKit/TUIContact/tuicontact')// Include the conversation list feature module (basic feature module)include ':tuiconversation'project(':tuiconversation').projectDir = new File(settingsDir, '../TUIKit/TUIConversation/tuiconversation')// Include the search feature module (To use this module, you need to purchase the Ultimate Edition)include ':tuisearch'project(':tuisearch').projectDir = new File(settingsDir, '../TUIKit/TUISearch/tuisearch')// Include the group feature moduleinclude ':tuigroup'project(':tuigroup').projectDir = new File(settingsDir, '../TUIKit/TUIGroup/tuigroup')// Include the community topic feature module (To use this module, you need to purchase the Ultimate Edition)include ':tuicommunity'project(':tuicommunity').projectDir = new File(settingsDir, '../TUIKit/TUICommunity/tuicommunity')// Include the audio/video call feature moduleinclude ':tuicallkit'project(':tuicallkit').projectDir = new File(settingsDir, '../TUIKit/TUICallKit/tuicallkit')// Include the video conference moduleinclude ':tuiroomkit' project(':tuiroomkit').projectDir = new File(settingsDir, '../TUIKit/TUIRoomKit/tuiroomkit')// Include speech-to-text plugin, supported from version 7.5include ':tuivoicetotextplugin' project(':tuivoicetotextplugin').projectDir = new File(settingsDir, '../TUIKit/TUIVoiceToTextPlugin/tuivoicetotextplugin')// Include customer service plugin, supported from version 7.6include ':tuicustomerserviceplugin' project(':tuicustomerserviceplugin').projectDir = new File(settingsDir, '../TUIKit/TUICustomerServicePlugin/tuicustomerserviceplugin')// Include chatbot plugin, supported from version 7.7include ':tuichatbotplugin' project(':tuichatbotplugin').projectDir = new File(settingsDir, '../TUIKit/TUIChatBotPlugin/tuichatbotplugin')// Include chat message translation plugin, supported from version 7.2 (Value-added feature activation is required. Please contact Tencent Cloud sales)include ':tuitranslationplugin'project(':tuitranslationplugin').projectDir = new File(settingsDir, '../TUIKit/TUITranslationPlugin/tuitranslationplugin')// Include emoji reaction plugin, supported from version 7.8 (To use this module, you need to purchase the Ultimate Edition)include ':tuiemojiplugin'project(':tuiemojiplugin').projectDir = new File(settingsDir, '../TUIKit/TUIEmojiPlugin/tuiemojiplugin')
build.gradle
in App:dependencies {api project(':tuiconversation')api project(':tuicontact')api project(':tuichat')api project(':tuisearch')api project(':tuigroup')api project(':tuicommunity')api project(':tuicallkit')api project(':tuiroomkit')// Integrate speech-to-text plugin, supported from version 7.5api project(':tuivoicetotextplugin')// Integrate customer service plugin, supported from version 7.6api project(':tuicustomerserviceplugin')// Integrate chatbot plugin, supported from version 7.7api project(':tuichatbotplugin')// Integrate translation plugin, supported from version 7.2 (Value-added feature activation is required. Please contact Tencent Cloud sales)api project(':tuitranslationplugin')// Integrate emoji reaction plugin, supported from version 7.8 (To use this module, you need to purchase the Ultimate Edition)api project(':tuiemojiplugin')// Integrate group chain plugin, supported from version 7.1api "com.tencent.imsdk:tuigroupnote-plugin:7.8.5484"// Integrate group voting plugin, supported from version 7.1api "com.tencent.imsdk:tuipoll-plugin:7.8.5484"// Integrate session grouping plugin, supported from version 7.3api "com.tencent.imsdk:tuiconversationgroup-plugin:7.8.5484"// Integrate session tagging plugin, supported from version 7.3api "com.tencent.imsdk:tuiconversationmark-plugin:7.8.5484"// Integrate message push plugin, supported from version 7.6api 'com.tencent.timpush:timpush:7.8.5484'// Integrate the corresponding manufacturer's push package as neededapi 'com.tencent.timpush:fcm:7.8.5484'api 'com.tencent.timpush:xiaomi:7.8.5484'api 'com.tencent.timpush:meizu:7.8.5484'api 'com.tencent.timpush:oppo:7.8.5484'api 'com.tencent.timpush:vivo:7.8.5484'api 'com.tencent.timpush:huawei:7.8.5484'api 'com.tencent.timpush:honor:7.8.5484'}
gradle.properties
file to automatically convert third-party libraries to use AndroidX:android.enableJetifier=true
build.gradle
file (in the same level as settings.gradle
) of the root project to add the Maven repository and Kotlin support: buildscript {repositories {mavenCentral()maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }}dependencies {classpath 'com.android.tools.build:gradle:7.0.0'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"}}
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"}}
classicui
folder stores the classic version UI files, and the `minimalistui` folder stores the minimalist version UI files. If you are to integrate the minimalist version UIs, directly delete the `classicui` folder and delete `Activity` and `Service` corresponding to the classic version UIs in the AndroidManifest.xml
file.// Called when Login is clicked on the user UITUILogin.login(context, sdkAppID, userID, userSig, new TUICallback() {@Overridepublic void onError(final int code, final String desc) {}@Overridepublic void onSuccess() {}});
Application
class must be passed in via context
. Otherwise, some images cannot be loaded.activity_main.xml
:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><androidx.viewpager2.widget.ViewPager2android:id="@+id/view_pager"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight = "1"/></LinearLayout>
FragmentAdapter.java
to work with ViewPager2 to display the conversation and contacts UIs.import androidx.annotation.NonNull;import androidx.fragment.app.Fragment;import androidx.fragment.app.FragmentActivity;import androidx.fragment.app.FragmentManager;import androidx.lifecycle.Lifecycle;import androidx.viewpager2.adapter.FragmentStateAdapter;import java.util.List;public class FragmentAdapter extends FragmentStateAdapter {private static final String TAG = FragmentAdapter.class.getSimpleName();private List<Fragment> fragmentList;public FragmentAdapter(@NonNull FragmentActivity fragmentActivity) {super(fragmentActivity);}public FragmentAdapter(@NonNull Fragment fragment) {super(fragment);}public FragmentAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) {super(fragmentManager, lifecycle);}public void setFragmentList(List<Fragment> fragmentList) {this.fragmentList = fragmentList;}@NonNull@Overridepublic Fragment createFragment(int position) {if (fragmentList == null || fragmentList.size() <= position) {return new Fragment();}return fragmentList.get(position);}@Overridepublic int getItemCount() {return fragmentList == null ? 0 : fragmentList.size();}}
TUIConversationFragment
and contact list TUIContactFragment
UI data are already encapsulated in TUI components, and UIs can be used as easily as common Android fragments.onCreate
method in MainActivity.java
:List<Fragment> fragments = new ArrayList<>();// Add the minimalist version of conversation UI provided by TUIConversationfragments.add(new TUIConversationMinimalistFragment());// Add the minimalist version of contacts UI provided by TUIContactfragments.add(new TUIContactMinimalistFragment());ViewPager2 mainViewPager = findViewById(R.id.view_pager);FragmentAdapter fragmentAdapter = new FragmentAdapter(this);fragmentAdapter.setFragmentList(fragments);mainViewPager.setOffscreenPageLimit(2);mainViewPager.setAdapter(fragmentAdapter);mainViewPager.setCurrentItem(0, false);
List<Fragment> fragments = new ArrayList<>();// Add the classic version of conversation UI provided by TUIConversationfragments.add(new TUIConversationFragment());// Add the classic version of contacts UI provided by TUIContactfragments.add(new TUIContactFragment());ViewPager2 mainViewPager = findViewById(R.id.view_pager);FragmentAdapter fragmentAdapter = new FragmentAdapter(this);fragmentAdapter.setFragmentList(fragments);mainViewPager.setOffscreenPageLimit(2);mainViewPager.setAdapter(fragmentAdapter);mainViewPager.setCurrentItem(0, false);
Bundle param = new Bundle(); param.putInt(TUIConstants.TUIChat.CHAT_TYPE, isGroup ? V2TIMConversation.V2TIM_GROUP : V2TIMConversation.V2TIM_C2C); // If it's C2C chat, chatID is the other person's UserID; if it's Group chat, chatID is the GroupIDparam.putString(TUIConstants.TUIChat.CHAT_ID, chatID); if (isGroup) { TUICore.startActivity("TUIGroupChatMinimalistActivity", param); } else { TUICore.startActivity("TUIC2CChatMinimalistActivity", param); }
Bundle param = new Bundle(); param.putInt(TUIConstants.TUIChat.CHAT_TYPE, isGroup ? V2TIMConversation.V2TIM_GROUP : V2TIMConversation.V2TIM_C2C); // If it's C2C chat, chatID is the other party's UserID; if it's Group chat, chatID is the GroupIDparam.putString(TUIConstants.TUIChat.CHAT_ID, chatID); if (isGroup) { TUICore.startActivity("TUIGroupChatActivity", param); } else { TUICore.startActivity("TUIC2CChatActivity", param); }
Fragment fragment;// If it's C2C chat, chatID is the other person's UserID; if it's Group chat, chatID is the GroupIDif (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 C2C chat, chatID is the other person's UserID; if it's Group chat, chatID is the GroupIDif (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();
Video Call | Audio Call |
| |
TUICallKit
dependency to the build.gradle
file in App:api project(':tuicallkit')
Starting a Call via a Message Page | Starting a Call via a Contact Profile Page |
| |
Voice Message Recorded by the System | Voice Message with AI-based Noise Reduction and Automatic Gain Control Recorded by TUICallkit |
| |
allowBackup
is false
by default, indicating that the backup and restore feature of the app is disabled.
You can delete the allowBackup
property from the AndroidManifest.xml
file to disable the backup and restore feature. You can also add tools:replace="android:allowBackup"
to the application
node of the AndroidManifest.xml
file to overwrite the Chat SDK configuration with your own configuration. <manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"package="com.tencent.qcloud.tuikit.myapplication"><applicationandroid: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>
local.properties
file. For example:
ndk.dir=/Users/***/Library/Android/sdk/ndk/16.1.4479499
MultiDex
support in the build.gradle
file in App and add multiDexEnabled true
and the corresponding dependencies:android {defaultConfig {...minSdkVersion 19targetSdkVersion 30multiDexEnabled true}...}dependencies {implementation "androidx.multidex:multidex:2.0.1"}
public class MyApplication extends SomeOtherApplication {@Overrideprotected void attachBaseContext(Context base) {super.attachBaseContext(base);MultiDex.install(this);}}
# Avoid deleting code logic -dontshrink -dontoptimize# Avoid aliasing TUIKit-keep class com.tencent.qcloud.** { *; }
Was this page helpful?