We’ve been tinkering with Beacons on Android in the last few weeks. With the release of Android 4.3, Bluetooth Low Energy (BLE) is supported but there are some nasty gremlins with the BLE implementation that required our team to do workarounds. Matt from our Android team did a talk at the Seattle Android Meetup on the topic recently (slides coming soon). Here are a few examples of the issues the team came across:
- For device scanning – a core BLE scenario – the API provides no timeout so you have to write a timer from scratch.
- When a device is scanned and found, the callback returns multiple times for the same device, which must be handled.
- If you connect during a scan, the scan terminates
- If you scan whilst you have active connections, the connections terminate
- BluetoothAdaptor has to be reset, or subsequent scans may return nothing
- Handset periodically returns “Bluetooth Share has Stopped” requiring a factory reset (occurred monthly during our testing in the Lab).
As you can see there’s a fair amount of work that needs to be done in order to get BLE scenarios working smoothly. That’s where our Ratio Labs Android Beacon Library comes in handy to help. Here’s the overview of the features:
- Implements BLE as an android service
- Requests done via AIDL with a service connection
- Responses sent via BroadcastReceivers
- Allows persistent device interface cross-activity.
- Hides all the nasty stuff
- Wraps Bluetooth classes in parcelable classes so they can be passed between activities.
- Less than 20 calls on a single object
- Supports connection retries
You can download the library from our Github here: https://github.com/RatioLabs/BLEService