Agent 7 + Agent 8: - CLAUDE.md 项目上下文 - 各 module README (core/im/push/update/webview/log) - XWebViewStandardHandlers.kt 补全标准 JSBridge handler
94 行
2.5 KiB
Markdown
94 行
2.5 KiB
Markdown
# sdk-core
|
||
|
||
XuqmGroup Android SDK 核心模块。提供 SDK 初始化、HTTP 请求、Token 管理、文件操作、通用工具。
|
||
|
||
## 依赖
|
||
|
||
```kotlin
|
||
implementation("com.xuqm:sdk-core:VERSION")
|
||
```
|
||
|
||
## 初始化
|
||
|
||
### 方式 A — ContentProvider 自动初始化(推荐)
|
||
|
||
将 `config.xuqm` 放入 `src/main/assets/xuqm/`,SDK 在 App 启动时自动读取并初始化。
|
||
|
||
```kotlin
|
||
// XuqmInitializerProvider 自动触发,无需代码
|
||
```
|
||
|
||
### 方式 B — 手动初始化
|
||
|
||
```kotlin
|
||
// Application.onCreate() 中:
|
||
XuqmSDK.initialize(context, appKey = "xxx")
|
||
XuqmSDK.initialize(context, appKey = "xxx", platformUrl = "https://xxx")
|
||
```
|
||
|
||
## API
|
||
|
||
### XuqmSDK(全局单例)
|
||
|
||
| API | 说明 |
|
||
|-----|------|
|
||
| `XuqmSDK.initialize(context, appKey, platformUrl?, logLevel?)` | 手动初始化 |
|
||
| `XuqmSDK.awaitInitialization()` | 等待平台配置拉取(coroutine) |
|
||
| `XuqmSDK.isInitialized()` | 检查是否已初始化 |
|
||
| `XuqmSDK.setUserInfo(info)` | 设置用户信息,触发所有子模块登录 |
|
||
| `XuqmSDK.setUserInfo(null)` | 登出,触发全局登出 |
|
||
| `XuqmSDK.getUserId()` | 获取当前 userId |
|
||
| `XuqmSDK.getUserInfo()` | 获取当前用户信息 |
|
||
| `XuqmSDK.appKey` | 当前 appKey |
|
||
| `XuqmSDK.platformConfig` | 平台配置(init 后可用) |
|
||
| `XuqmSDK.logApiUrl` | 日志服务地址(从平台配置获取) |
|
||
| `XuqmSDK.logEnabled` | 是否启用日志上报 |
|
||
| `XuqmSDK.useLocalServiceEndpoints(ip)` | 切换本地联调环境 |
|
||
| `XuqmSDK.tokenStore` | Token 存储(EncryptedSharedPreferences) |
|
||
|
||
### XuqmUserInfo
|
||
|
||
```kotlin
|
||
data class XuqmUserInfo(
|
||
val userId: String, // 必填
|
||
val userSig: String? = null, // IM 登录凭证(可选)
|
||
val name: String? = null,
|
||
val phone: String? = null,
|
||
val avatar: String? = null,
|
||
)
|
||
```
|
||
|
||
### TokenStore
|
||
|
||
基于 `EncryptedSharedPreferences` 持久化存储。
|
||
|
||
```kotlin
|
||
XuqmSDK.tokenStore.saveToken("eyJ...")
|
||
val token = XuqmSDK.tokenStore.getToken()
|
||
XuqmSDK.tokenStore.clear()
|
||
```
|
||
|
||
### ApiClient
|
||
|
||
基于 OkHttp 5 + Retrofit 3,自动附加 Bearer Token。
|
||
|
||
```kotlin
|
||
val service = RetrofitFactory.create(MyApiService::class.java)
|
||
```
|
||
|
||
### FileSDK
|
||
|
||
文件上传、下载、打开的统一入口(`com.xuqm.sdk.file`)。
|
||
|
||
```kotlin
|
||
// 上传
|
||
val result = FileSDK.upload(context, uri, onProgress = { /* 0-100 */ })
|
||
val result = FileSDK.uploadBytes(fileName, mimeType, bytes, onProgress)
|
||
|
||
// 下载
|
||
val file = FileSDK.download(context, url, fileName, destination, notificationTitle, onProgress)
|
||
|
||
// 打开
|
||
FileSDK.openFile(context, file)
|
||
```
|