Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Chat-Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ The project uses a single app to combine a variety of functionalities.Each funct

- Physical Android device or Android simulator with Android 5.0+
- Android Studio (latest version recommended)
- JDK (1.8+)
- JDK (17+)

### Steps to run

1. Clone this project to local
2. In Android Studio, open `/Chat-Android/`.
3. Sync the project with Gradle files.
4. If you want to use your own App Key for the experience, you can edit the `Chat-Android/app/src/main/res/values/strings.xml` file.
- Replace `YOUR APP KEY` with your App KEY.
4. If you want to use your own App ID for the experience, you can edit the `Chat-Android/app/src/main/res/values/strings.xml` file.
- Replace `YOUR APP ID` with your App ID.
- Replace `YOUR LOGIN URL` with the address of the App Server you built to get Agora Chat Token.
- Replace `YOUR REGISTER USER URL` with the address of the registered Agora Chat user on the App Server you built.
```xml
<string name="app_key">YOUR APP KEY</string>
<string name="app_id">YOUR APP ID</string>
<string name="login_url">YOUR LOGIN URL</string>
<string name="register_url">YOUR REGISTER URL</string>
```
Expand Down
8 changes: 4 additions & 4 deletions Chat-Android/README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ _[English](README.md) | 中文_

- 真实的 Android 设备或 Android 虚拟机
- Android Studio (推荐最新版)
- JDK (1.8以上)
- JDK (17及以上)

### 运行步骤

1. 克隆本项目到本地
2. 在 Android Studio 中,打开 /Chat-Android/。
3. 将项目与 Gradle 文件同步。
4. 如果你想使用自己的 App Key 进行体验,你可以编辑 `Chat-Android/app/src/main/res/values/strings.xml` 文件。
- 将 `YOUR APP KEY` 替换为你的 App Key
4. 如果你想使用自己的 App ID 进行体验,你可以编辑 `Chat-Android/app/src/main/res/values/strings.xml` 文件。
- 将 `YOUR APP ID` 替换为你的 App ID
- 将 `YOUR LOGIN URL` 替换为你搭建的 App Server 获取 Agora Chat Token 的地址。
- 将 `YOUR REGISTER USER URL` 替换为你搭建的 App Server 注册 Agora Chat 用户的地址。
```xml
<string name="app_key">YOUR APP KEY</string>
<string name="app_id">YOUR APP ID</string>
<string name="login_url">YOUR LOGIN URL</string>
<string name="register_url">YOUR REGISTER URL</string>
```
Expand Down
29 changes: 16 additions & 13 deletions Chat-Android/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,19 @@ To enable your app to send and receive messages between individual users, do the
In `app/java/io.agora.agorachatquickstart/MainActivity`, before adding the following lines after `AppCompatActivity {`, ensure you delete the `onCreate` function created by default.

```java
// Replaces <Your username>, <Your token>, and <Your AppKey> with your own App Key, user ID, and user token generated in Agora Console.
// Replaces <Your username>, <Your token>, and <Your App ID> with your own App ID, user ID, and user token generated in Agora Console.
private static final String USERNAME = "<Your username>";
private static final String TOKEN = "<Your token>";
private static final String APP_KEY = "<Your AppKey>";
private static final String APP_ID = "<Your App ID>";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initSDK();
if(!initSDK()) {
return;
}
initListener();
}
```
Expand All @@ -295,21 +297,22 @@ To enable your app to send and receive messages between individual users, do the
((TextView)findViewById(R.id.tv_log)).setMovementMethod(new ScrollingMovementMethod());
}
// Initializes the SDK.
private void initSDK() {
private boolean initSDK() {
ChatOptions options = new ChatOptions();
// Gets your App Key applied from Agora Console.
if(TextUtils.isEmpty(APP_KEY)) {
Toast.makeText(MainActivity.this, "You should set your AppKey first!", Toast.LENGTH_SHORT).show();
return;
// Gets your App ID applied from Agora Console.
if(TextUtils.isEmpty(APP_ID)) {
Toast.makeText(MainActivity.this, "You should set your App ID first!", Toast.LENGTH_SHORT).show();
return false;
}
// Sets your App Key to options.
options.setAppKey(APP_KEY);
// Sets your App ID to options.
options.setAppId(APP_ID);
// Initializes the Agora Chat SDK.
ChatClient.getInstance().init(this, options);
// Makes the Agora Chat SDK debuggable.
ChatClient.getInstance().setDebugMode(true);
// Shows the current user.
((TextView)findViewById(R.id.tv_username)).setText("Current user: "+USERNAME);
return true;
}
```

Expand Down Expand Up @@ -468,7 +471,7 @@ To enable your app to send and receive messages between individual users, do the
To validate the peer-to-peer messaging you have just integrated into your app using Agora Chat, perform the following operations:

1. Log in
a. In the [`MainActivity`](#sign-in) file, replace the placeholders of `USERNAME`, `TOKEN`, and `APP_KEY` to the user Id, Agora token, and App Key of the sender (Som).
a. In the [`MainActivity`](#sign-in) file, replace the placeholders of `USERNAME`, `TOKEN`, and `APP_ID` to the user Id, Agora token, and App ID of the sender (Som).
b. In **Android Studio**, select the device to run the project and click **Run 'app'**.
c. On your simulator or physical device, click **SIGN IN** to log in with the sender account.
![](https://web-cdn.agora.io/docs-files/1665302124510)
Expand All @@ -481,14 +484,14 @@ To validate the peer-to-peer messaging you have just integrated into your app us
Click **SIGN OUT** to log out of the sender account.

4. Receive the message
a. After signing out, change the values of `USERNAME`, `TOKEN`, and `APP_KEY` to the user Id, Agora token, and App Key of the receiver (Neil) in the [`MainActivity`](#sign-in) file.
a. After signing out, change the values of `USERNAME`, `TOKEN`, and `APP_ID` to the user Id, Agora token, and App ID of the receiver (Neil) in the [`MainActivity`](#sign-in) file.
b. Run the app on another Android device or simulator with the receiver account and receive the message "How are you doing?" sent in step 2.
![](https://web-cdn.agora.io/docs-files/1665302134132)


## Next Steps

For demonstration purposes, Agora Chat uses temporary tokens generated from Agora Console for authentication in this guide. In a production context, the best practice is for you to deploy your own token server, use your own [App Key](./enable_agora_chat?platform=Android#get-the-information-of-the-agora-chat-project) to generate a token, and retrieve the token on the client side to log in to Agora. To see how to implement a server that generates and serves tokens on request, see [Generate a User Token](./generate_user_tokens).
For demonstration purposes, Agora Chat uses temporary tokens generated from Agora Console for authentication in this guide. In a production context, the best practice is for you to deploy your own token server, use your own [App ID](./enable_agora_chat?platform=Android#get-the-information-of-the-agora-chat-project) to generate a token, and retrieve the token on the client side to log in to Agora. To see how to implement a server that generates and serves tokens on request, see [Generate a User Token](./generate_user_tokens).


## See also
Expand Down
30 changes: 15 additions & 15 deletions Chat-Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
namespace = 'io.agora.agorachatquickstart'
compileSdk = 35

defaultConfig {
applicationId "io.agora.agorachatquickstart"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
applicationId = "io.agora.agorachatquickstart"
minSdk = 24
targetSdk = 35
versionCode = 1
versionName = "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -23,19 +23,19 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'com.google.android.material:material:1.14.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'

// Required: Agora Chat SDK
implementation 'io.agora.rtc:chat-sdk:latest.release'
Expand Down
7 changes: 4 additions & 3 deletions Chat-Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.agora.agorachatquickstart">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand Down Expand Up @@ -31,7 +30,9 @@
<activity android:name="io.agora.agorachatquickstart.MainActivity">

</activity>
<activity android:name="io.agora.agorachatquickstart.NavigationActivity" >
<activity
android:name="io.agora.agorachatquickstart.NavigationActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,40 @@ public class MainActivity extends AppCompatActivity {
private static final String USERNAME = "";
// Gets token from Agora Console or generates by your app server
private static final String TOKEN = "";
// Gets AppKey from Agora Console
private static final String APP_KEY = "";
// Gets App ID from Agora Console
private static final String APP_ID = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initSDK();
if(!initSDK()) {
return;
}
initListener();
}

private void initView() {
((TextView)findViewById(R.id.tv_log)).setMovementMethod(new ScrollingMovementMethod());
}

private void initSDK() {
private boolean initSDK() {
ChatOptions options = new ChatOptions();
// Get your appkey applied from Agora Console
if(TextUtils.isEmpty(APP_KEY)) {
Toast.makeText(MainActivity.this, "You should set your AppKey first!", Toast.LENGTH_SHORT).show();
return;
// Get your App ID applied from Agora Console
if(TextUtils.isEmpty(APP_ID)) {
Toast.makeText(MainActivity.this, "You should set your App ID first!", Toast.LENGTH_SHORT).show();
return false;
}
// Set your appkey to options
options.setAppKey(APP_KEY);
// Set your App ID to options
options.setAppId(APP_ID);
// To initialize Agora Chat SDK
ChatClient.getInstance().init(this, options);
// Make Agora Chat SDK debuggable
ChatClient.getInstance().setDebugMode(true);
// Show current user
((TextView)findViewById(R.id.tv_username)).setText("Current user: "+USERNAME);
return true;
}

private void initListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class NavigationActivity extends AppCompatActivity {
R.string.send_audio_message,
R.string.fetch_messages_from_server
};
private static final Class<?>[] targetActivities = {
MainActivity.class,
ImportMessagesActivity.class,
SendAudioMessageActivity.class,
FetchMessagesFromServerActivity.class
};
private RecyclerView rvList;
private Activity mContext;

Expand Down Expand Up @@ -56,25 +62,8 @@ public void onBindViewHolder(@NonNull NavigationViewHolder holder, int position)
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
switch (titles[myPosition]) {
case R.string.quick_start :
intent = new Intent(mContext, MainActivity.class);
startActivity(intent);
break;
case R.string.import_messages :
intent = new Intent(mContext, ImportMessagesActivity.class);
startActivity(intent);
break;
case R.string.send_audio_message :
intent = new Intent(mContext, SendAudioMessageActivity.class);
startActivity(intent);
break;
case R.string.fetch_messages_from_server :
intent = new Intent(mContext, FetchMessagesFromServerActivity.class);
startActivity(intent);
break;
}
Intent intent = new Intent(mContext, targetActivities[myPosition]);
startActivity(intent);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public class AccountHelper {
*/
public static void initSDK(Context context) {
ChatOptions options = new ChatOptions();
// Set your appkey applied from Agora Console
String sdkAppkey = context.getString(R.string.app_key);
if(TextUtils.isEmpty(sdkAppkey)) {
Toast.makeText(context, "You should set your AppKey first!", Toast.LENGTH_SHORT).show();
// Set your App ID applied from Agora Console
String sdkAppId = context.getString(R.string.app_id);
if(TextUtils.isEmpty(sdkAppId)) {
Toast.makeText(context, "You should set your App ID first!", Toast.LENGTH_SHORT).show();
return;
}
// Set your appkey to options
options.setAppKey(sdkAppkey);
// Set your App ID to options
options.setAppId(sdkAppId);
// Set you to use HTTPS only
options.setUsingHttpsOnly(true);
options.setAutoLogin(false);
Expand Down
2 changes: 1 addition & 1 deletion Chat-Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">AgoraChatQuickstart</string>

<string name="app_key">41117440#383391</string>
<string name="app_id">Your Agora App ID</string>
</resources>
27 changes: 4 additions & 23 deletions Chat-Android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
plugins {
id 'com.android.application' version '9.0.0' apply false
}

task clean(type: Delete) {
delete rootProject.buildDir
tasks.register('clean', Delete) {
delete rootProject.layout.buildDirectory
}
Loading