altbeaconibeacon-android

AltBeacon Not Finding Beacons


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


Solution

  • The most likely reasons are:

    1. Your route.route.uuid does not match the UUID of the transmitter.
    2. You didn't set the BeaconLayout if you are using iBeacon. (By default, the library only detects AltBeacon)
    3. You didn't obtain the required location permission from the user to be able to look for bluetooth beacons, causing the operating system to block detections.

    I wrote a checklist to help troubleshoot problems like this.