diff --git a/androidExample/.gradle/8.9/checksums/checksums.lock b/androidExample/.gradle/8.9/checksums/checksums.lock new file mode 100644 index 0000000..afbed7b Binary files /dev/null and b/androidExample/.gradle/8.9/checksums/checksums.lock differ diff --git a/androidExample/.gradle/8.9/checksums/md5-checksums.bin b/androidExample/.gradle/8.9/checksums/md5-checksums.bin new file mode 100644 index 0000000..ef69f27 Binary files /dev/null and b/androidExample/.gradle/8.9/checksums/md5-checksums.bin differ diff --git a/androidExample/.gradle/8.9/checksums/sha1-checksums.bin b/androidExample/.gradle/8.9/checksums/sha1-checksums.bin new file mode 100644 index 0000000..796b017 Binary files /dev/null and b/androidExample/.gradle/8.9/checksums/sha1-checksums.bin differ diff --git a/androidExample/.gradle/8.9/fileHashes/fileHashes.lock b/androidExample/.gradle/8.9/fileHashes/fileHashes.lock new file mode 100644 index 0000000..cee87b5 Binary files /dev/null and b/androidExample/.gradle/8.9/fileHashes/fileHashes.lock differ diff --git a/androidExample/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/androidExample/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..8ec7a3f Binary files /dev/null and b/androidExample/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/androidExample/.gradle/buildOutputCleanup/cache.properties b/androidExample/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..4dd464e --- /dev/null +++ b/androidExample/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Tue Jan 20 11:09:22 CST 2026 +gradle.version=8.9 diff --git a/androidExample/.gradle/config.properties b/androidExample/.gradle/config.properties new file mode 100644 index 0000000..99f1b76 --- /dev/null +++ b/androidExample/.gradle/config.properties @@ -0,0 +1,2 @@ +#Tue Jan 20 11:09:14 GMT+08:00 2026 +java.home=C\:\\Program Files\\Android\\Android Studio1\\jbr diff --git a/androidExample/local.properties b/androidExample/local.properties new file mode 100644 index 0000000..c68afdc --- /dev/null +++ b/androidExample/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Tue Jan 20 11:09:14 GMT+08:00 2026 +sdk.dir=C\:\\Users\\86181\\AppData\\Local\\Android\\Sdk diff --git a/androidExampleDemo/.gitignore b/androidExampleDemo/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/androidExampleDemo/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/androidExampleDemo/README.md b/androidExampleDemo/README.md new file mode 100644 index 0000000..2b621e0 --- /dev/null +++ b/androidExampleDemo/README.md @@ -0,0 +1,180 @@ +# Android Agent调用示例 + +这是一个Android示例项目,演示如何调用情感分析Agent。 + +## 📋 项目结构 + +``` +androidExample/ +├── app/ +│ ├── src/ +│ │ └── main/ +│ │ ├── java/com/example/agentclient/ +│ │ │ ├── MainActivity.kt +│ │ │ ├── AgentService.kt +│ │ │ ├── models/ +│ │ │ │ ├── AgentRequest.kt +│ │ │ │ ├── AgentResponse.kt +│ │ │ │ └── ExecutionResponse.kt +│ │ │ └── utils/ +│ │ │ └── ApiClient.kt +│ │ └── res/ +│ │ ├── layout/ +│ │ │ └── activity_main.xml +│ │ └── values/ +│ │ └── strings.xml +│ └── build.gradle.kts +├── build.gradle.kts +├── settings.gradle.kts +└── README.md +``` + +## 🚀 快速开始 + +### 1. 配置API地址 + +在 `app/src/main/java/com/example/agentclient/utils/ApiClient.kt` 中修改: + +```kotlin +private const val BASE_URL = "http://your-server-ip:8037" +``` + +### 2. 配置Agent ID + +在 `MainActivity.kt` 中修改: + +```kotlin +private val AGENT_ID = "your-agent-id" // 情感分析Agent的ID +``` + +### 3. 运行项目 + +1. 使用Android Studio打开项目 +2. 同步Gradle依赖 +3. 运行到Android设备或模拟器 + +## 📱 功能特性 + +- ✅ 用户登录 +- ✅ 调用Agent API +- ✅ 实时显示执行状态 +- ✅ 显示Agent回复 +- ✅ 错误处理 + +## 🔧 依赖库 + +- Retrofit2:网络请求 +- OkHttp:HTTP客户端 +- Gson:JSON解析 +- Coroutines:异步处理 + +## 📝 使用说明 + +1. **登录** + - 应用启动后会自动登录(使用配置的用户名和密码) + - 登录成功后可以开始使用Agent + +2. **发送消息** + - 在输入框中输入文本 + - 点击"发送"按钮 + - 等待Agent处理并返回结果 + +3. **查看结果** + - Agent的回复会显示在消息列表中 + - 执行状态会实时更新 + +## 🔑 API说明 + +### 登录API +``` +POST /api/v1/auth/login +Content-Type: application/x-www-form-urlencoded + +username=admin&password=123456 +``` + +### 执行Agent API +``` +POST /api/v1/executions +Authorization: Bearer +Content-Type: application/json + +{ + "agent_id": "agent-id", + "input_data": { + "query": "用户输入", + "USER_INPUT": "用户输入" + } +} +``` + +### 获取执行状态API +``` +GET /api/v1/executions/{execution_id}/status +Authorization: Bearer +``` + +### 获取执行结果API +``` +GET /api/v1/executions/{execution_id} +Authorization: Bearer +``` + +## 🎯 示例:调用情感分析Agent + +```kotlin +// 1. 登录获取token +val token = agentService.login("admin", "123456") + +// 2. 执行Agent +val execution = agentService.executeAgent( + agentId = "sentiment-analysis-agent-id", + userInput = "这个产品真的很棒!" +) + +// 3. 轮询获取结果 +while (true) { + val status = agentService.getExecutionStatus(execution.id) + if (status.status == "completed") { + val result = agentService.getExecutionResult(execution.id) + println("情感分析结果: ${result.output_data}") + break + } + delay(1000) // 等待1秒 +} +``` + +## 📦 构建要求 + +- Android Studio Hedgehog | 2023.1.1 或更高版本 +- JDK 17 或更高版本 +- Android SDK API 24 或更高版本 +- Gradle 8.0 或更高版本 + +## 🔒 安全注意事项 + +1. **不要硬编码密码**:生产环境应该使用安全的认证方式 +2. **使用HTTPS**:生产环境必须使用HTTPS +3. **Token管理**:妥善保管和刷新Token +4. **网络安全配置**:Android 9+需要配置网络安全策略 + +## 🐛 故障排除 + +### 问题1:网络连接失败 +- 检查API地址是否正确 +- 检查设备网络连接 +- 检查服务器是否运行 + +### 问题2:登录失败 +- 检查用户名和密码是否正确 +- 检查服务器认证服务是否正常 + +### 问题3:Agent执行失败 +- 检查Agent ID是否正确 +- 检查Agent是否已发布 +- 查看服务器日志获取详细错误信息 + +## 📚 相关文档 + +- [Agent使用说明](../Agent使用说明.md) +- [API文档](../backend/API_DOCUMENTATION.md) diff --git a/androidExampleDemo/app/.gitignore b/androidExampleDemo/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/androidExampleDemo/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/androidExampleDemo/app/build.gradle b/androidExampleDemo/app/build.gradle new file mode 100644 index 0000000..a4b19ff --- /dev/null +++ b/androidExampleDemo/app/build.gradle @@ -0,0 +1,64 @@ +plugins { + alias(libs.plugins.android.application) + id 'dagger.hilt.android.plugin' +} + +android { + namespace 'com.example.demo' + compileSdk 34 + + defaultConfig { + applicationId "com.example.demo" + minSdk 26 + targetSdk 34 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } +} + +dependencies { + // 基础Android库 + implementation libs.appcompat + implementation libs.material + + // 生命周期和ViewModel + implementation libs.lifecycle.viewmodel + implementation libs.lifecycle.livedata + + // Room数据库 + implementation libs.room.runtime + annotationProcessor libs.room.compiler + + // 网络库 + implementation libs.retrofit + implementation libs.retrofit.gson + implementation libs.okhttp.logging + + // 依赖注入 + implementation libs.hilt.android + annotationProcessor libs.hilt.compiler + + // 工作管理器 + implementation libs.work.runtime + + // 蓝牙库 + implementation libs.ble + + // 测试库 + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core +} \ No newline at end of file diff --git a/androidExampleDemo/app/proguard-rules.pro b/androidExampleDemo/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/androidExampleDemo/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/androidExampleDemo/app/src/androidTest/java/com/example/obd/ExampleInstrumentedTest.java b/androidExampleDemo/app/src/androidTest/java/com/example/obd/ExampleInstrumentedTest.java new file mode 100644 index 0000000..ce711fe --- /dev/null +++ b/androidExampleDemo/app/src/androidTest/java/com/example/obd/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.obd; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.obd", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/androidExampleDemo/app/src/main/AndroidManifest.xml b/androidExampleDemo/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..213b282 --- /dev/null +++ b/androidExampleDemo/app/src/main/AndroidManifest.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/androidExampleDemo/app/src/main/java/com/example/demo/MainActivity.java b/androidExampleDemo/app/src/main/java/com/example/demo/MainActivity.java new file mode 100644 index 0000000..9077aa8 --- /dev/null +++ b/androidExampleDemo/app/src/main/java/com/example/demo/MainActivity.java @@ -0,0 +1,22 @@ +package com.example.demo; + +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +public class MainActivity extends AppCompatActivity { + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + } + +} \ No newline at end of file diff --git a/androidExampleDemo/app/src/main/res/drawable/button_outline.xml b/androidExampleDemo/app/src/main/res/drawable/button_outline.xml new file mode 100644 index 0000000..3007ba8 --- /dev/null +++ b/androidExampleDemo/app/src/main/res/drawable/button_outline.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/androidExampleDemo/app/src/main/res/drawable/button_primary.xml b/androidExampleDemo/app/src/main/res/drawable/button_primary.xml new file mode 100644 index 0000000..4c35579 --- /dev/null +++ b/androidExampleDemo/app/src/main/res/drawable/button_primary.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/androidExampleDemo/app/src/main/res/drawable/button_secondary.xml b/androidExampleDemo/app/src/main/res/drawable/button_secondary.xml new file mode 100644 index 0000000..0e9391f --- /dev/null +++ b/androidExampleDemo/app/src/main/res/drawable/button_secondary.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/androidExampleDemo/app/src/main/res/drawable/data_card_background.xml b/androidExampleDemo/app/src/main/res/drawable/data_card_background.xml new file mode 100644 index 0000000..104a453 --- /dev/null +++ b/androidExampleDemo/app/src/main/res/drawable/data_card_background.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/androidExampleDemo/app/src/main/res/drawable/ic_launcher_background.xml b/androidExampleDemo/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/androidExampleDemo/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/androidExampleDemo/app/src/main/res/drawable/ic_launcher_foreground.xml b/androidExampleDemo/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/androidExampleDemo/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/androidExampleDemo/app/src/main/res/layout/activity_device_discovery.xml b/androidExampleDemo/app/src/main/res/layout/activity_device_discovery.xml new file mode 100644 index 0000000..d9c0b5d --- /dev/null +++ b/androidExampleDemo/app/src/main/res/layout/activity_device_discovery.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + +