I was trying to implement beacon scanning program, and i want the android BLE services to behave similar to iOS "didRangeBeacons" method,i.e, it should get called every one second. But in android there is no such method. But in android there is "leScanCallback" method that gets called very frequently with a scan period of less than a second. So is there any way that i can implement my functionality in leScanCallback method and increase its scan period interval to 1 second, so that it behaves similar to iOS's "didRangeBeacons" method.
*Also will it be the bad programming to continually scan beacon and increasing its scan interval in android?
Thanks in advance
It is important to understand that there is no native iBeacon support in Android. The Android leScanCallback
method is not at all an equivalent of the iOS didRangeBeacons
method.
The leScanCallback
method simply gives you a callback every time an advertising packet from a Bluetooth device is seen (devices with the connectable bit set in the advertisement are only given a callback the first time its Mac address is seen until you stop and restart scanning). Unless you stop and restart scanning on a timer, there is no scan period, and you get callbacks as the packets arrive. This can be many times a second.
When writing the open source Android iBeacon Library, I had to build all the functionality from scratch to make a didRangeBeaconsInRegion
callback that was the equivalent to what is in iOS. To do this, the library stops and restarts scanning about once a second and buffers the list of all iBeacons seen in the cycle, only calling the callback with the list of visible iBeacons at the end of the cycle. There are lots of other complexities not discussed here.
The code is free for you to review and modify, so I encourage you to do so if you want to roll your own.
来源:https://stackoverflow.com/questions/24180849/how-to-increase-the-scan-period-for-ble-devices-in-android