I am trying to implement the AltBeacon library to range beacons similarly to the way iOS does. However I am having trouble getting my app to recognize any beacons.
Here is my code:
onCreate:
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) {
}
}
Am I missing an element for it to range standard iBeacon BLE packets? Any help is appreciated.
Thanks
The most likely reasons are:
route.route.uuid
does not match the UUID of the transmitter.I wrote a checklist to help troubleshoot problems like this.