# Android

### 이 글에서는

GrowSpace Android SDK는 BLE 및 UWB 기반 실내 위치 기술을 Android 앱에 간편하게 통합할 수 있도록 설계된 개발 키트입니다. 거리 측정(Ranging)부터 RTLS 위치 추정까지 모두 하나의 클래스(`SpaceUwb`)로 제어할 수 있습니다.

***

### 주요 기능

* BLE + UWB 거리 측정 (Ranging)
* RTLS 기반 위치 추정 (x, y, z 계산)
* 실시간 장치 연결 / 해제 이벤트 제공

***

### 설치하기

#### Gradle 설정

```kotlin
dependencies {
    implementation("io.github.freegrowenterprise:SpaceSDK-Android:0.0.9")
}
```

#### 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.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.UWB_RANGING" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```

### 요구 사항

| 항목         | 조건                        |
| ---------- | ------------------------- |
| Android OS | Android 14 (API 34) 이상    |
| 언어         | Kotlin 1.9.22 (권장)        |
| 디바이스       | UWB 지원 Android 스마트폰       |
| 하드웨어       | GrowSpace UWB 제품군 (태그/앵커) |

***

### 초기화

```kotlin
val spaceUwb = SpaceUwb(context = applicationContext, activity = this)
```

***

### 거리 측정 시작

```kotlin
spaceUwb.startUwbRanging(
    maximumConnectionCount = 4,
    replacementDistanceThreshold = 8f,
    isConnectStrongestSignalFirst = true,
    onUpdate = { result ->
        Log.d("UWB", "device=${result.deviceName}, distance=${result.distance}m")
    },
    onDisconnect = { device ->
        Log.w("UWB", "Disconnected from ${device.deviceName}")
    }
)
```

### 거리 측정 중지

```kotlin
spaceUwb.stopUwbRanging { result ->
    if (result.isSuccess) {
        Log.i("UWB", "Ranging stopped")
    } else {
        Log.e("UWB", "Stop failed: ${result.exceptionOrNull()?.message}")
    }
}
```

***

### RTLS 위치 추정 시작

```kotlin
val anchorMap = mapOf(
    "FGU-0001" to Triple(0.0, 0.0, 0.0),
    "FGU-0002" to Triple(5.0, 0.0, 0.0),
    "FGU-0003" to Triple(0.0, 5.0, 0.0)
)

spaceUwb.startUwbRtls(
    anchorPositionMap = anchorMap,
    zCorrection = 1.0f,
    maximumConnectionCount = 4,
    replacementDistanceThreshold = 8f,
    isConnectStrongestSignalFirst = true,
    filterType = RtlsFilterType.AVERAGE,
    onResult = { location ->
        Log.d("RTLS", "x=${location.x}, y=${location.y}, z=${location.z}")
    },
    onFail = { error ->
        Log.e("RTLS", "Positioning failed: $error")
    },
    onDeviceRanging = { map ->
        map.forEach { (id, dist) ->
            Log.d("RTLS", "$id = $dist m")
        }
    }
)
```

***

### 배터리 정보 (추가 예정)

```kotlin
spaceUwb.battery { battery ->
    Log.i("Battery", "battery: $battery")
}
```

***

### 테스트 앱

공식 테스트 앱을 통해 SDK 기능을 손쉽게 검증할 수 있습니다.

* [GitHub](https://github.com/freegrowenterprise/SpaceSDK-Android-TestApp)
* [Google Play](https://play.google.com/store/apps/details?id=com.growspace.testapp\&pcampaignid=web_share)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://freegrow-1.gitbook.io/product-docs-kr/ko-mobile-kit-n1/uwb-n1-sdk/sdk/android.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
