Search code examples
bluetoothbluetooth-lowenergyibeaconibeacon-androidaltbeacon

IBeacon : Detect multiple beacons in background


As part of my project, I need to deploy a high number of beacons in a big city like Sydney or Melbourne. As user passes by one of these beacons, my app should perform a specific action. I plan to keep the UUID same for all beacons in my fleet, have a range of 1-20 major values based on the city site and have a different minor value for each beacon.

I have a gone through the background detection tutorial for iBeacon and have successfully tested with a single beacon.But what i am confused is do I have to define a region for each beacon in my code.

For testing, I have configured my beacon with following values - UUID - ABCD1234-DCBA-4321-5555-666677778888 major - 1 minor - 1

And my current region defining code looks like - Region region = new Region("backgroundRegion1", Identifier.parse("ABCD1234-DCBA-4321-5555-666677778888"),Identifier.parse("1"), Identifier.parse("1"));

Instead I want it to be detected with something like this (which i tried and seems to be not working) - Region region = new Region("backgroundRegion1", Identifier.parse("ABCD1234-DCBA-4321-5555-666677778888"),null, null);

Considering i will have a huge number of beacons, i just want to avoid to copy paste the same line of code.


Solution

  • I am working on a solution with a similar beacon implementation (one UUID, many major/minors). I have a few possible suggestions:

    1. You can do something like this How can I get beacon's data (UUID,Major,Minor) in `didEnterRegion` in altbeacon library?
    2. You could use the region id ("backgroundRegion1" in your example) in the didEnterRegion() call back to separate beacons. This assumes that the region ID is unique enough to correctly trigger app behavior

    A few things to watch out for

    1. didEnterRegion() seems to get called multiple times if the user is in range of multiple beacons at the same time.
    2. didExitRegion() only gets called if the user is out of range of ALL beacons
    3. The ranging solution in the link above will fire a callback as long as the user is in range of that beacon, so you'll need to do your own filtering

    Personally, I rely the most on David's solution in the link above