diff --git a/README.md b/README.md index 2df2f8ed..ccd54bad 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,51 @@ # Agora chat demo -This repository will help you learn how to use Agora chat SDK to implement a simple chat android application, like whatsapp or wechat. +This repository will help you learn how to use Agora chat SDK to implement a simple android chat app, like whatsapp or wechat. With this sample app, you can: -- Login chat server +- Log in to the chat server - Start a chat -- Manage conversation list +- Manage the conversation list - Add contacts - Join group chats -- Join chat rooms -- Add your contacts to your blacklist -- Send various types of messages, Such as: text, expression, picture, voice, file and so on -- Logout +- Add your contacts to your block list +- Send various types of messages, such as text, emoji, image, voice and file messages +- Log out of the chat server ## Prerequisites -* Make sure you have made the preparations mentioned in the [Agora Chat SDK quickstart](https://docs.agora.io/en/agora-chat/get-started/get-started-sdk?platform=android). -* Prepare the development environment: - * Java Development Kit (JDK) - * Android Studio 3.6 or later + +- Make sure you have made the preparations mentioned in the [Agora Chat SDK quickstart](https://docs.agora.io/en/agora-chat/get-started/get-started-sdk?platform=android). +- Prepare the development environment: + - Java Development Kit (JDK) + - Android Studio Flamingo | 2022.2.1 or later + ## Run the sample project -Follow these steps to run the sample project:\ -### 1. Clone the repository to your local machine. +Follow these steps to run the sample project: + +### 1. Clone the repository to your local device + ```java git clone git@github.com:AgoraIO-Usecase/AgoraChat-android.git ``` -### 2. Open the Android project with Android Studio. +### 2. Open the Android project with Android Studio -### 3. Configure keys. -Set your appkey applied from [Agora Developer Console](https://console.agora.io/) before calling ChatClient#init(). -```java -ChatOptions options = new ChatOptions(); -// Set your appkey -options.setAppKey("Your appkey"); -... -//initialization -ChatClient.getInstance().init(applicationContext, options); +### 3. Configure keys + +Set your appkey obtained from the [Agora Console](https://console.agora.io/) before calling ChatClient#init(). + +```kotlin +val chatOptions = ChatOptions().apply { + // Set your appkey + appKey = "Your appkey" + ... +} +// initialization +ChatClient.getInstance().init(context, chatOptions) ``` + For details, see the [prerequisites](https://docs.agora.io/en/agora-chat/get-started/get-started-sdk?platform=android) in Agora Chat SDK Guide. ## Precautions @@ -50,8 +57,10 @@ For details, see the [prerequisites](https://docs.agora.io/en/agora-chat/get-sta ``` ## Contact Us + - You can find full API document at [Document Center](https://docs.agora.io/en/agora-chat/overview/product-overview?platform=android) - You can file bugs about this demo at [issue](https://github.com/AgoraIO-Usecase/AgoraChat-android/issues) ## License + The MIT License (MIT). diff --git a/app-kotlin/.gitignore b/app-kotlin/.gitignore new file mode 100644 index 00000000..b61e41ab --- /dev/null +++ b/app-kotlin/.gitignore @@ -0,0 +1,2 @@ +/build +/src/google-services.json \ No newline at end of file diff --git a/app-kotlin/README.md b/app-kotlin/README.md new file mode 100644 index 00000000..68ad2da3 --- /dev/null +++ b/app-kotlin/README.md @@ -0,0 +1,292 @@ +# 快速开始 + +利用环信单群聊 UIKit,你可以轻松实现单群和群聊。本文介绍如何快速实现在单聊会话中发送消息。 + +## 前提条件 + +### 开发环境要求 + +- Android Studio 4.0 及以上 +- Gradle 4.10.x 及以上 +- targetVersion 26 及以上 +- Android SDK API 21 及以上 +- JDK 11 及以上 + +## 项目准备 + +下面将介绍将单群聊 UIKit 引入项目中的必要环境配置。 + +1. 用 **Android Studio** 创建一个[新的项目](https://developer.android.com/studio/projects/create-project),在 **Phone and Tablet** 标签选择 **Empty Views Activity**,**Minimum SDK** 选择 **API 21: Android 5.0 (Lollipop)**,**Language** 选择 **Kotlin**。创建项目成功后,请确保项目同步完成。 + +2. 检查工程是否引入 **mavenCentral** 仓库。 + + a. Gradle 7.0 之前 + 在 `/Gradle Scripts/build.gradle.kts(Project: )`文件内,检查是否有 **mavenCentral** 仓库。 + ```kotlin + buildscript { + repositories { + mavenCentral() + } + } + ``` + b. Gradle 7.0 之后 + 在 `/Gradle Scripts/settings.gradle.kts(Project Settings)`文件内,检查是否有 **mavenCentral** 仓库。 + ```kotlin + dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + mavenCentral() + } + } + ``` +3. 在项目中引入单群聊 UIKit + +从 GitHub 获取[单群聊 UIKit](https://github.com/easemob/chatuikit-android) 源码,按照下面的方式集成: + +- 在根目录 `settings.gradle.kts` 文件(/Gradle Scripts/settings.gradle.kts)中添加如下代码: + +```kotlin +include(":ease-im-kit") +project(":ease-im-kit").projectDir = File("../chatuikit-android/ease-im-kit") +``` + +- 在 app 的 `build.gradle.kts` 文件(/Gradle Scripts/build.gradle)中添加如下代码: + +```kotlin +//chatuikit-android +implementation(project(mapOf("path" to ":ease-im-kit"))) +``` + +4. 防止代码混淆 + +在 `/Gradle Scripts/proguard-rules.pro` 文件中添加如下代码: + + ``` + -keep class com.hyphenate.** {*;} + -dontwarn com.hyphenate.** + ``` +## 实现单聊发消息 + +这部分将介绍如何通过单群聊 UIKit 一步一步的实现单聊发送消息的。 + +### 创建页面相关 + +1. 打开 `app/res/values/strings.xml` 文件,并替换为如下内容: + +```xml + + quickstart + + [您申请的appkey] + + +``` +这里需要注意的是,需要将 **app_key** 替换为您申请的 appkey。 + +2. 打开 `app/res/layout/activity_main.xml` 文件,并替换为如下内容: + +```xml + + + + + + + +