Search code examples
javaandroidaltbeaconandroid-ibeacon

Scanning for beacons multiple times in a second (Android-Java)


I'm using the following method (taken from the android beacon library)

public void didRangeBeaconsInRegion(final Collection<Beacon> collection, Region region)

This callback method "detects" beacons every 1.1 seconds. To be more precise, it fires every 1.1 seconds. My beacon device (Kontakt i.o). Sends packets every 200ms. I've found out that there isn't a way to somehow decrease the firing interval of the above method so my question is, is there an alternative for this method so that I can do my distance calculations more often.

Basically I'm providing the RSSI and TxPower as arguments and doing some more calculation to make the distancing more accurate so I would like to get my RSSI every 200ms not every second...


Solution

  • Create an instance of the BeaconManager, you can set a couple of methods regarding the scanning:

    BeaconManager manager = BeaconManager.getInstanceForApplication(context);
    manager.setBackgroundScanPeriod(milliseconds); //defaults to 10
    manager.setBackgroundBetweenScanPeriod(miliseconds); //Period between scans
    manager.setForegroundBetweenScanPeriod(miliseconds); //Period between scans
    manager.setForegroundScanPeriod(milliseconds); //defaults to 1.1
    

    You can find some more methods when you look at the BeaconManager source.