我尝试使用 BLE 获取两个移动设备之间的距离,我知道这是一项常见任务,我们可以使用RSSI和txPower找出距离。
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
}
}
}
有人对我的问题有建议吗?任何回应将不胜感激。