Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the scan period for BLE devices in Android?

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

like image 629
HeadOnn Avatar asked Jun 12 '14 09:06

HeadOnn


People also ask

What is scan interval in BLE?

Interval between the start of two consecutive scan windows. 10 ms to 10.24 s.

How do you scan BLE on Android?

To find BLE devices, you use the startScan() method. This method takes a ScanCallback as a parameter. You must implement this callback, because that is how scan results are returned.

How many BLE devices can Android connect?

x protocol SPEC, when the iPhone/Android phone play as role of BLE central mode, the limitation to have active connection at the same time is up to 8 devices.

What is BLE settings Android?

Android provides built-in platform support for Bluetooth Low Energy (BLE) in the central role and provides APIs that apps can use to discover devices, query for services, and transmit information. Common use cases include the following: Transferring small amounts of data between nearby devices.


1 Answers

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.

like image 83
davidgyoung Avatar answered Nov 01 '22 11:11

davidgyoung