When Apple announced the specifications for iBeacons it caused quite a buzz. The ability to accurately find and use the location of a person inside a building opened the door for innovative new apps.
In order to detect iBeacons in Android we had to run a Bluetooth scan, determine which devices were beacons, notify the app that a beacon was detected, and react to that beacon. This process took many steps so most of the manufacturers of iBeacons built their own libraries for developers. The problem was these libraries only worked with their own iBeacons. We needed a solution that would work with any iBeacon, was dead simple, and easily customizable. That’s when we decided to roll our own iBeacon library, Lantern.
See the challenge, develop the solution.
Lantern allows for developers to easily add the ability to detect iBeacons and notify other parts of their app to react accordingly. With a few lines of code the service is running, ready to detect iBeacons, and able to send out notifications. When the user’s phone comes within the proximity of an iBeacon, a broadcast is sent out. When a broadcast receiver receives the broadcast, it contains a beacon object. This object knows the distance away from the beacon, UUID, mac address, major, minor, and many other attributes relating to that beacon. That information can then be processed and the app can respond accordingly. Using the default settings for Lantern, the service will broadcast all iBeacons that come into proximity. There will also be a broadcast sent when the iBeacon has not been detected for two minutes. All of this can be customized when the service is first initialized. All you have to do to initialize the service is:
BeaconServiceController.startBeaconService(this, 20000, 60000, 7000, 5000, null);
The parameters are context, scan interval, expiration interval, scan time, fast scan interval, and UUID filter.
- Context: Context of the app.
- Scan interval: Time in milliseconds between scans when no beacon has yet to be detected.
- Expiration interval: Amount of time in milliseconds after a beacon is no longer detected before the expiration broadcast is sent.
- Scan time: Time in milliseconds a scan takes.
- Fast scan interval: Amount of time in milliseconds between scans while there are still active beacons.
- UUID filter: UUID of the beacons you want to be notified about. If this is null, then you will be notified about all iBeacons that are detected.
This is just a short summary of the library, what it does, why we felt we had to make it, and how it is used.
For more information about the library visit our GitHub Repository.
Sam is an Android Software Engineer on #TeamMyriad and when not coding, loves to play with his cat.