162 lines
2.9 KiB
Markdown
162 lines
2.9 KiB
Markdown
# 移动端开发
|
|
|
|
完成配对与权限接入,下载示例 App 并查看开源仓库,集成通知与同步。
|
|
|
|
## 平台支持
|
|
|
|
觉远创智 SDK 支持以下移动端平台:
|
|
|
|
### Android
|
|
|
|
使用 Kotlin/Java 开发,支持蓝牙和 Wi-Fi 配对,需要相应权限。
|
|
|
|
**环境要求:**
|
|
- Android 5.0 (API 21) 及以上
|
|
- Kotlin 1.5+ 或 Java 8+
|
|
|
|
**安装:**
|
|
|
|
```gradle
|
|
dependencies {
|
|
implementation 'com.smartglasses:mobile-sdk:2.1.0'
|
|
}
|
|
```
|
|
|
|
**初始化:**
|
|
|
|
```kotlin
|
|
val mobileSDK = MobileSDK.getInstance(context)
|
|
mobileSDK.initialize(
|
|
apiKey = "your-api-key",
|
|
appId = "your-app-id"
|
|
)
|
|
```
|
|
|
|
**设备配对:**
|
|
|
|
```kotlin
|
|
// 扫描设备
|
|
mobileSDK.scanDevices { devices ->
|
|
// 选择设备进行配对
|
|
mobileSDK.pairDevice(devices[0]) { success ->
|
|
if (success) {
|
|
println("配对成功")
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### iOS
|
|
|
|
使用 Swift 开发,需要麦克风和通知权限,支持设备绑定。
|
|
|
|
**环境要求:**
|
|
- iOS 12.0 及以上
|
|
- Swift 5.0+
|
|
|
|
**安装:**
|
|
|
|
```ruby
|
|
pod 'SmartGlassesMobileSDK', '~> 2.1.0'
|
|
```
|
|
|
|
**初始化:**
|
|
|
|
```swift
|
|
import SmartGlassesMobileSDK
|
|
|
|
let mobileSDK = MobileSDK.shared
|
|
mobileSDK.initialize(
|
|
apiKey: "your-api-key",
|
|
appId: "your-app-id"
|
|
)
|
|
```
|
|
|
|
**设备配对:**
|
|
|
|
```swift
|
|
// 扫描设备
|
|
mobileSDK.scanDevices { devices in
|
|
// 选择设备进行配对
|
|
mobileSDK.pairDevice(devices[0]) { success in
|
|
if success {
|
|
print("配对成功")
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Web
|
|
|
|
使用 Web API 进行开发,支持进度上报。
|
|
|
|
**安装:**
|
|
|
|
```bash
|
|
npm install smartglasses-mobile-sdk
|
|
```
|
|
|
|
**使用:**
|
|
|
|
```javascript
|
|
import { MobileSDK } from 'smartglasses-mobile-sdk'
|
|
|
|
const mobileSDK = new MobileSDK({
|
|
apiKey: 'your-api-key',
|
|
appId: 'your-app-id'
|
|
})
|
|
|
|
// 初始化
|
|
await mobileSDK.initialize()
|
|
|
|
// 扫描设备
|
|
const devices = await mobileSDK.scanDevices()
|
|
|
|
// 配对设备
|
|
await mobileSDK.pairDevice(devices[0])
|
|
```
|
|
|
|
## 权限配置
|
|
|
|
### Android
|
|
|
|
在 `AndroidManifest.xml` 中添加权限:
|
|
|
|
```xml
|
|
<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" />
|
|
```
|
|
|
|
### iOS
|
|
|
|
在 `Info.plist` 中添加权限说明:
|
|
|
|
```xml
|
|
<key>NSBluetoothAlwaysUsageDescription</key>
|
|
<string>需要蓝牙权限以连接智能眼镜设备</string>
|
|
<key>NSMicrophoneUsageDescription</key>
|
|
<string>需要麦克风权限以进行语音交互</string>
|
|
```
|
|
|
|
## 通知集成
|
|
|
|
```kotlin
|
|
// Android 示例
|
|
mobileSDK.notifications.sendNotification(
|
|
title = "新消息",
|
|
content = "您有一条新消息",
|
|
icon = R.drawable.notification_icon
|
|
)
|
|
```
|
|
|
|
```swift
|
|
// iOS 示例
|
|
mobileSDK.notifications.sendNotification(
|
|
title: "新消息",
|
|
body: "您有一条新消息"
|
|
)
|
|
```
|
|
|