Scanning iBeacon and Eddystone Using Android BLE Scanner
Contributor - 18 November 2020 -
Contributor - 18 November 2020 -
This blog will introduce you to Bluetooth Low Energy and will cover all the end-use application areas where it is used. Furthermore, the blog will also walk you through different kinds of BLE beacons and popular beacon protocols.
In the latter half of the article, we will create a demo android application to test out 2 BLE Beacon protocol, one from Apple and one from Google. But, let us first go through some basic definitions and an overview of BLE and Beacons before jumping onto the coding part.
Bluetooth Low Energy is a wireless personal area network technology designed by Bluetooth SIG. The Bluetooth SIG identifies different markets for low energy technology, particularly in the field of smart home, health, sport, and fitness sectors. Some of the key advantages include:
Bluetooth Low Energy (BLE), available from Android API 18(4.3 — Jelly Bean), and later creates short connections between devices to transfer bursts of data. BLE when not connected it remains in sleep mode. This is because as compared to Classic Bluetooth it utilizes less power by providing lower bandwidth. It is ideal for applications such as a heart-rate monitor or a wireless keyboard. To use BLE, devices need to have a chipset that supports BLE. Talking about BLE Beacons, Bluetooth Beacons are physical transmitters – a class of BLE devices that broadcast their identifiers on nearby electronic devices.
These beacons can be used for many proximity-related applications such as –
It can be used for many other use cases as well. For instance, you can place a BLE tag in your key and then can use your mobile phone to search for it if it’s inside a cupboard or just lying under the sofa.
Now, we will see how we can scan for Apple’s iBeacon and Google’s Eddystone-UID by creating a demo android application.
Create a new project and choose the template of your choice.
I chose “Empty Activity”.
There is no extra BLE library dependency as such for scanning for BLE beacons.
Open AndroidManifest.xml and add the following in the manifest element.
<uses-feature> tag with required as “true” means that this app requires BLE hardware to work with hence Google play will make sure that this app is only visible to devices that have the BLE hardware Available.
<uses-permission> tag is required to get the permission to use the Bluetooth hardware with Coarse location in Low energy mode.
Coarse location permission is needed for Bluetooth low energy scanning mode. Hence we should make sure that we have the required permission provided by the user.
Check whether got the permission else to show the dialog letting the user know why we need this permission.
Setting up Bluetooth API
Initialize the BluetoothManager to get the instance of BluetoothAdapter for getting BluetoothLeScanner, which is required to perform scan related operations for Bluetooth LE devices.
We can have the button to control the start and stop of the BLE scanner.
We should create a Beacon class to hold the different info we will be parsing from ScanResult from onScanResult callback.
Extracting Eddystone UID packet info if there is any.
Eddystone UID: A unique, static ID with a 10-byte Namespace component and a 6-byte Instance component.
Extracting iBeacon packet info if there is any.
iBeacon: A unique, static ID with a 16-byte Proximity UUID component and a 2-byte Major component, and a 2-byte Minor component.
Figure- Start screen
Figure- Start screen with the options
Figure- Result screen with Eddystone UID, iBeacon, generic BLE devices
BLE beacons iBeacon and Eddystone-UID are different from each other, however can be used for any of the proximity-related applications. It is because, at the application level, both of them solve similar problems using different Bluetooth profiles.
Eddystone do have a different type of packets to solve a different problem like-
For more details and an in-depth view, you can find the code here