【发布时间】:2020-04-27 21:35:09
【问题描述】:
我正在尝试实现 AltBeacon 库以类似于 iOS 的方式来范围信标。但是,我无法让我的应用识别任何信标。
这是我的代码:
创建:
beaconManager = BeaconManager.getInstanceForApplication(this) beaconManager.bind(this) var region = Region(route.route.uuid, null, null, null) beaconManager.startMonitoringBeaconsInRegion(region)
onBeaconServiceConnect
override fun onBeaconServiceConnect() {
beaconManager.removeAllRangeNotifiers()
beaconManager.addRangeNotifier(object : RangeNotifier {
override fun didRangeBeaconsInRegion(
beacons: Collection<Beacon>,
region: Region?
) {
if (beacons.size > 0) {
println("I see ${beacons.size} beacons")
log += "The first beacon I see is about " + beacons.iterator().next().getDistance()
.toString() + " meters away."
log += "I see ${beacons.size} beacons.\n"
debugLog()
}
else
{
println("I see 0 beacons")
log += "I see 0 beacons\n"
debugLog()
}
}
})
try {
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", null, null, null))
} catch (e: RemoteException) {
}
}
我是否缺少一个元素来覆盖标准 iBeacon BLE 数据包?任何帮助表示赞赏。
谢谢
【问题讨论】: