onBeaconsDiscovered called several times at once and in unexpected periods


#1

Hi, I have a problem with the onBeaconsDiscovered function. It appears that SOMETIMES it is being called more than once, here a log:

02-08 15:05:16.768 21247-21247/com.xxx.app D/xxx: Starting ranging scan
02-08 15:05:27.000 21247-21247/com.xxx.app D/xxx: Discovered beacons: 0
02-08 15:05:27.035 21247-21247/com.xxx.app D/xxx: Discovered beacons: 0
02-08 15:05:27.035 21247-21247/com.xxx.app D/xxx: Discovered beacons: 0
02-08 15:05:37.122 21247-21247/com.xxx.app D/xxx: Discovered beacons: 1
02-08 15:05:47.194 21247-21247/com.xxx.app D/xxx: Discovered beacons: 0
02-08 15:05:47.201 21247-21247/com.xxx.app D/xxx: Discovered beacons: 0
02-08 15:05:58.172 21247-21247/com.xxx.app D/xxx: Discovered beacons: 1
02-08 15:06:08.201 21247-21247/com.xxx.app D/xxx: Discovered beacons: 1
02-08 15:06:12.255 21247-21247/com.xxx.app D/xxx: Discovered beacons: 0
02-08 15:06:12.266 21247-21247/com.xxx.app D/xxx: Discovered beacons: 1
02-08 15:06:22.403 21247-21247/com.xxx.app D/xxx: Discovered beacons: 1

You can see that the method is being invoked several times within a second. E.g. at the top it has been called 3 times in a row, once 35ms apart and then 0ms apart. This is odd, as I have only invoked startRanging() once for sure. Also, if that was the problem driver, then it should always call the method 3 times, but it appears to be very random how often it is being called as you can see in the logs. Unfortunately this randomness is very bad, as I need a reliable indicator if beacons are being discovered. The result even seem to change across the different invocations, as can be seen in the 15:06:12.255 and 15:06:12.266 timestamp.

Furthermore, I have set the foreground scan period to 10s / 20s:

beaconManager.setForegroundScanPeriod(10000, 20000);

Based on other forum entries I was led to believe that onBeaconsDiscovered should only be called once every 10s + 20s = 30s in this case. However, as you can see, it seems to be called 1 or more times, roughly every 10 seconds… Is this expected behaviour?

I am using a Nexus 5X for testing.

Thank you for your replies


#2

Hello
Have you found an answer?