Android includes fully native support for the Bluetooth framework, which allows a device to wirelessly exchange data with other Bluetooth devices.
- Some of the operations that can be performed with the Bluetooth API are:
- Discover other Bluetooth devices
- Get a list of paired devices
- Handle connection and disconnection events
- Set device visibility so that it is discoverable by other devices
- Implement strategies to manage Bluetooth power consumption, such as activation and deactivation, as necessary.
- Wirelessly exchange data between connected devices.
How have we implemented Bluetooth connection within our projects?
We implemented Bluetooth connectivity with a tobacco smoke sensor company. These sensors were located in the electrical outlets of guest rooms (such as hotels, Airbnb's, hostels, etc.) and sent an alert through a mobile app when there was smoke detected.
To install these sensors, we developed a connection interface via Bluetooth between the sensors and the mobile app to be able to set up the WIFI connection that would allow alerts to be sent to the server.
Bluetooth connection handling was done with the native Android API, using the BluetoothAdapter class.
Handling Beacons at Ballast Lane Applications
First things first, what is a beacon? A beacon is an electronic device that sends signals through a low-power Bluetooth connection so that smartphones, tablets and other devices perform specific actions when they are in its vicinity.
The most common beacons are the size of small stones, but they can be as small as a sticker. They can use batteries (AA, AAA, or button type), plug into an electrical outlet, or even draw power from a USB connector. Depending on the type of beacon, they can connect to devices that are from a few centimeters to 10 meters away.
How have we implemented beacons in our projects?
Below are 2 specific use cases: Proximity marketing: Within a construction store (similar to Home Depot) the user would be able to receive notifications with offers regarding the products displayed in the aisle they were walking through. Process optimization: the use case consisted of keeping track of the times that a hotel's maintenance employees entered the rooms to configure the smoke sensors.
In what other cases can a Beacon be used?
Museums: Placing a beacon near each work of art in the rooms allows visitors to receive relevant information when they are nearby. Prevention: In dangerous activities, it could encourage workers to wear appropriate safety equipment, complying with safety standards. Contactless payments: These beacons make contactless payments easier, saving staff time and streamlining customer service.
Practical Implementation
To detect beacons on Android, we use the android-beacons-library, created by the AltBeacon developers. This library is easily configured to detect a variety of beacons, including popular ones such as iBeacon, Eddystone, and others.
In this example we are going to create a class that handles the beacon recognition service, we will call it BeaconsHelper that will implement BeaconConsumer and use BeaconManager to configure the interaction with the beacons.
The BeaconConsumer interface asks us to complete the onBeaconServiceConnect() method where we will begin to detect the beacons and receive information about them using RangeNotifier.
Finally, the Rangenotifier interface enables the didRangeBeaconsInRegion() method. This method is called every time there is a beacon recognition and it gives us information about it, such as its identifier and the distance at which it is located.
With this code it is possible to start detecting beacons and perform actions such as opening a URL, showing a notification or starting a background process within the app.
What if I don't have a real Beacon to test?
No problem, if you have another Android device within your reach, you can use it to simulate and emit signals like a Beacon. This is the app that we recommend and use at Ballastlane for this purpose: