diff --git a/androidExampleDemo/README.md b/androidExampleDemo/README.md index cf4f8c0..731ea20 100644 --- a/androidExampleDemo/README.md +++ b/androidExampleDemo/README.md @@ -1,15 +1,26 @@ +<<<<<<< HEAD # Android Agent调用示例 (Java版本) 这是一个使用Java开发的Android示例项目,演示如何调用情感分析Agent。 +======= +# Android Agent调用示例 + +这是一个Android示例项目,演示如何调用情感分析Agent。 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 ## 📋 项目结构 ``` +<<<<<<< HEAD androidExampleDemo/ +======= +androidExample/ +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 ├── app/ │ ├── src/ │ │ └── main/ │ │ ├── java/com/example/agentclient/ +<<<<<<< HEAD │ │ │ ├── MainActivity.java │ │ │ ├── models/ │ │ │ │ ├── Agent.java @@ -31,6 +42,24 @@ androidExampleDemo/ ├── build.gradle ├── settings.gradle ├── gradle.properties +======= +│ │ │ ├── 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 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 └── README.md ``` @@ -38,6 +67,7 @@ androidExampleDemo/ ### 1. 配置API地址 +<<<<<<< HEAD 在 `app/src/main/java/com/example/agentclient/utils/ApiClient.java` 中修改: ```java @@ -52,6 +82,20 @@ private static final String BASE_URL = "http://your-server-ip:8037"; private static final String USERNAME = "admin"; private static final String PASSWORD = "123456"; private static final String AGENT_NAME = "情感分析Agent"; // Agent名称 +======= +在 `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 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 ``` ### 3. 运行项目 @@ -73,7 +117,11 @@ private static final String AGENT_NAME = "情感分析Agent"; // Agent名称 - Retrofit2:网络请求 - OkHttp:HTTP客户端 - Gson:JSON解析 +<<<<<<< HEAD - AndroidX:Android支持库 +======= +- Coroutines:异步处理 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 ## 📝 使用说明 @@ -129,6 +177,7 @@ Authorization: Bearer ## 🎯 示例:调用情感分析Agent +<<<<<<< HEAD ```java // 1. 登录获取token Call loginCall = ApiClient.getService().login("admin", "123456"); @@ -186,6 +235,28 @@ loginCall.enqueue(new Callback() { // 处理错误 } }); +======= +```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秒 +} +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 ``` ## 📦 构建要求 @@ -195,12 +266,15 @@ loginCall.enqueue(new Callback() { - Android SDK API 24 或更高版本 - Gradle 8.0 或更高版本 +<<<<<<< HEAD ## 💻 开发语言 - **Java 17** - 主要开发语言 - 使用Retrofit进行网络请求 - 使用Gson进行JSON解析 +======= +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 ## 🔒 安全注意事项 1. **不要硬编码密码**:生产环境应该使用安全的认证方式 diff --git a/androidExampleDemo/app/build.gradle b/androidExampleDemo/app/build.gradle index a369e63..f5d3cf3 100644 --- a/androidExampleDemo/app/build.gradle +++ b/androidExampleDemo/app/build.gradle @@ -1,4 +1,5 @@ plugins { +<<<<<<< HEAD id 'com.android.application' } @@ -9,6 +10,19 @@ android { defaultConfig { applicationId "com.example.agentclient" minSdk 24 +======= + alias(libs.plugins.android.application) + id 'dagger.hilt.android.plugin' +} + +android { + namespace 'com.example.demo' + compileSdk 34 + + defaultConfig { + applicationId "com.example.demo" + minSdk 26 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 targetSdk 34 versionCode 1 versionName "1.0" @@ -22,6 +36,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } +<<<<<<< HEAD compileOptions { sourceCompatibility JavaVersion.VERSION_17 @@ -30,10 +45,16 @@ android { buildFeatures { viewBinding true +======= + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 } } dependencies { +<<<<<<< HEAD // Android Core implementation 'androidx.core:core:1.12.0' implementation 'androidx.appcompat:appcompat:1.6.1' @@ -56,3 +77,37 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } +======= + // 基础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 +} +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/app/proguard-rules.pro b/androidExampleDemo/app/proguard-rules.pro index 695c294..52eafae 100644 --- a/androidExampleDemo/app/proguard-rules.pro +++ b/androidExampleDemo/app/proguard-rules.pro @@ -1,6 +1,7 @@ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. +<<<<<<< HEAD # Retrofit -keepattributes Signature, InnerClasses, EnclosingMethod @@ -31,3 +32,23 @@ # Keep model classes -keep class com.example.agentclient.models.** { *; } +======= +# +# 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 +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/app/src/main/AndroidManifest.xml b/androidExampleDemo/app/src/main/AndroidManifest.xml index f85b76b..77d0c13 100644 --- a/androidExampleDemo/app/src/main/AndroidManifest.xml +++ b/androidExampleDemo/app/src/main/AndroidManifest.xml @@ -2,16 +2,39 @@ +<<<<<<< HEAD + + + + + + + + + + + + + + + >>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" +<<<<<<< HEAD android:theme="@style/Theme.AppCompat.Light.DarkActionBar" android:usesCleartextTraffic="true" tools:targetApi="31"> @@ -27,3 +50,28 @@ +======= + android:theme="@style/Theme.AppCompat.Light.NoActionBar" + android:usesCleartextTraffic="true" + android:networkSecurityConfig="@xml/network_security_config" + tools:targetApi="31"> + + + + + + + + + + + + + +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 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/layout/activity_main.xml b/androidExampleDemo/app/src/main/res/layout/activity_main.xml index a1fed58..7ed8596 100644 --- a/androidExampleDemo/app/src/main/res/layout/activity_main.xml +++ b/androidExampleDemo/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,5 @@ +<<<<<<< HEAD +======= + + + + + +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/app/src/main/res/values/strings.xml b/androidExampleDemo/app/src/main/res/values/strings.xml index 7c0a3c1..3c92391 100644 --- a/androidExampleDemo/app/src/main/res/values/strings.xml +++ b/androidExampleDemo/app/src/main/res/values/strings.xml @@ -1,4 +1,33 @@ +<<<<<<< HEAD Agent客户端 +======= + + 个人知库 + 欢迎使用OBD诊断工具 + 连接蓝牙OBD设备 + 连接WiFi OBD + 设置 + 准备就绪 + 需要蓝牙权限才能连接OBD设备 + 需要位置权限才能扫描蓝牙设备 + 设备不支持蓝牙 + 蓝牙未启用 + 正在搜索OBD设备... + + + 开始采集 + 停止采集 + 上传数据 + 查看历史 + 采集中... + 已停止 + 已暂停 + 数据已上传 + 上传失败 + 没有数据需要上传 + 请在系统蓝牙设置中搜索并连接您的OBD设备,然后返回应用 + +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/app/src/main/res/xml/network_security_config.xml b/androidExampleDemo/app/src/main/res/xml/network_security_config.xml index ad0734b..6a7f74f 100644 --- a/androidExampleDemo/app/src/main/res/xml/network_security_config.xml +++ b/androidExampleDemo/app/src/main/res/xml/network_security_config.xml @@ -1,6 +1,10 @@ +<<<<<<< HEAD +======= + +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/build.gradle b/androidExampleDemo/build.gradle index b84d244..9153b0a 100644 --- a/androidExampleDemo/build.gradle +++ b/androidExampleDemo/build.gradle @@ -1,4 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +<<<<<<< HEAD buildscript { repositories { google() @@ -20,3 +21,9 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } +======= +plugins { + alias(libs.plugins.android.application) apply false + id 'com.google.dagger.hilt.android' version '2.48.1' apply false +} +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/gradle.properties b/androidExampleDemo/gradle.properties index 5ae443b..d0a90d8 100644 --- a/androidExampleDemo/gradle.properties +++ b/androidExampleDemo/gradle.properties @@ -1,4 +1,27 @@ # Project-wide Gradle settings. +<<<<<<< HEAD org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true android.enableJetifier=true +======= +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 diff --git a/androidExampleDemo/gradle/wrapper/gradle-wrapper.properties b/androidExampleDemo/gradle/wrapper/gradle-wrapper.properties index 42defcc..d931fd2 100644 --- a/androidExampleDemo/gradle/wrapper/gradle-wrapper.properties +++ b/androidExampleDemo/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,13 @@ +<<<<<<< HEAD distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip networkTimeout=10000 +======= +#Mon Oct 27 16:52:14 CST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/androidExampleDemo/settings.gradle~7c5f94d47066e9f9fb4cd23e74fe34d53d326684 b/androidExampleDemo/settings.gradle~7c5f94d47066e9f9fb4cd23e74fe34d53d326684 new file mode 100644 index 0000000..6ce3b80 --- /dev/null +++ b/androidExampleDemo/settings.gradle~7c5f94d47066e9f9fb4cd23e74fe34d53d326684 @@ -0,0 +1,23 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "obd" +include ':app'