首页 > 解决方案 > 使用 Android BLE(蓝牙低功耗)计算距离

问题描述

我尝试使用 BLE 获取两个移动设备之间的距离,我知道这是一项常见任务,我们可以使用RSSItxPower找出距离。

txPower但是我在 android BLE中获得价值时遇到了问题。它总是返回 127 (TX_POWER_NOT_PRESENT),虽然我已经添加了AdvertiseData

val data = AdvertiseData.Builder().setIncludeDeviceName(false).setIncludeTxPowerLevel(true)
            .addServiceUuid(pUuid).build() 

下面是用于获取的代码块txPower

private fun processScanResult(scanResult: ScanResult?) {

            var txPower: Int? = null

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                txPower = scanResult?.txPower
                if (txPower == 127) {
                    txPower = null
                }
            }
        }

有人对我的问题有建议吗?任何回应将不胜感激。

标签: androidbluetooth-lowenergyble-txpower

解决方案


推荐阅读