This commit is contained in:
rjb
2026-01-20 14:25:07 +08:00
12 changed files with 323 additions and 0 deletions

View File

@@ -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网络请求
- OkHttpHTTP客户端
- GsonJSON解析
<<<<<<< HEAD
- AndroidXAndroid支持库
=======
- Coroutines异步处理
>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684
## 📝 使用说明
@@ -129,6 +177,7 @@ Authorization: Bearer <token>
## 🎯 示例调用情感分析Agent
<<<<<<< HEAD
```java
// 1. 登录获取token
Call<TokenResponse> loginCall = ApiClient.getService().login("admin", "123456");
@@ -186,6 +235,28 @@ loginCall.enqueue(new Callback<TokenResponse>() {
// 处理错误
}
});
=======
```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<TokenResponse>() {
- Android SDK API 24 或更高版本
- Gradle 8.0 或更高版本
<<<<<<< HEAD
## 💻 开发语言
- **Java 17** - 主要开发语言
- 使用Retrofit进行网络请求
- 使用Gson进行JSON解析
=======
>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684
## 🔒 安全注意事项
1. **不要硬编码密码**:生产环境应该使用安全的认证方式

View File

@@ -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

View File

@@ -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

View File

@@ -2,16 +2,39 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<<<<<<< HEAD
<!-- -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
=======
<!-- OBD -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- 针对Android 12+ -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
>>>>>>> 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 @@
</application>
</manifest>
=======
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DeviceDiscoveryActivity"
android:exported="false"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
</application>
</manifest>
>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684

View File

@@ -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);
}
}

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<<<<<<< HEAD
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -73,3 +74,12 @@
</LinearLayout>
</LinearLayout>
=======
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684

View File

@@ -1,4 +1,33 @@
<<<<<<< HEAD
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Agent客户端</string>
</resources>
=======
<resources>
<string name="app_name">个人知库</string>
<string name="welcome_message">欢迎使用OBD诊断工具</string>
<string name="connect_bluetooth">连接蓝牙OBD设备</string>
<string name="connect_wifi">连接WiFi OBD</string>
<string name="settings">设置</string>
<string name="ready_status">准备就绪</string>
<string name="permission_bluetooth_required">需要蓝牙权限才能连接OBD设备</string>
<string name="permission_location_required">需要位置权限才能扫描蓝牙设备</string>
<string name="bluetooth_not_available">设备不支持蓝牙</string>
<string name="bluetooth_disabled">蓝牙未启用</string>
<string name="scanning_devices">正在搜索OBD设备...</string>
<!-- 数据采集相关 -->
<string name="start_collection">开始采集</string>
<string name="stop_collection">停止采集</string>
<string name="upload_data">上传数据</string>
<string name="view_history">查看历史</string>
<string name="collection_running">采集中...</string>
<string name="collection_stopped">已停止</string>
<string name="collection_paused">已暂停</string>
<string name="data_uploaded">数据已上传</string>
<string name="upload_failed">上传失败</string>
<string name="no_data_to_upload">没有数据需要上传</string>
<string name="bluetooth_settings_instruction">请在系统蓝牙设置中搜索并连接您的OBD设备然后返回应用</string>
</resources>
>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684

View File

@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<<<<<<< HEAD
<!-- HTTP使HTTPS -->
=======
<!-- 允许所有 HTTP 流量 -->
>>>>>>> 7c5f94d47066e9f9fb4cd23e74fe34d53d326684
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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'