I've written my own little BLE scanning service that is triggered via an alarm every 3-5 seconds. It scans for 1.1 seconds to get teh beacons around it and then transforms the RSSI signal into a rough proximity.
I am now considering the Radius Networks Android iBeacon service, but I am wondering how I could realize the same background scanning.
e.g.: I want the beacons scannign to start annd run in the background and receive Intents into a broadcast receiver to decide what I do with the beacons scanned.
Are there soem examples and is there an estimate how much battery this consumes?
An iBeacon is a device that emits a Bluetooth signal that can be detected by your devices. Companies can deploy iBeacon devices in environments where proximity detection is a benefit to users, and apps can use the proximity of beacons to determine an appropriate course of action.
Unlike iOS, Android does not have native iBeacon support. Due to this, to use iBeacon on Android, a developer either has to use an existing library or create code that parses BLE packets to find iBeacon advertisements. BLE support was introduced in Android Jelly Bean with major bug fixes in Android KitKat.
iBeacons are secure in the sense that they are very simple devices that do nothing but transmit a 3 part identifier (and a transmitter power measurement). They are always advertising unless you go out of your way to stop them.
We implemented this fusion workflow in an Android smartphone and conducted real-time experiments in a building floor. Two different routes with sharp turns were selected. The positioning accuracy of the iBeacon-based method is RMSE 2.75 m.
Radius Networks' Android iBeacon Library does exactly that. All you have to do to run it in the background is bind the IBeaconManager
to something with a long lifecycle. This can be a custom android.app.Application
object, or a Service of your own. Since you have already written your own service for your app, you could easily bind the IBeaconManager
to that service, and it would remain active in the background as long as the service runs. You could also use your service to send out broadcast intents if you wish, but for most use cases this is probably not necessary.
As for battery usage, the library's reference application has an example of how to set the background mode on the library so scans happen less often, saving battery. The pertinent code in that reference app is here:
@Override
protected void onPause() {
super.onPause();
if (iBeaconManager.isBound(this)) iBeaconManager.setBackgroundMode(this, true);
}
@Override
protected void onResume() {
super.onResume();
if (iBeaconManager.isBound(this)) iBeaconManager.setBackgroundMode(this, false);
}
Setting the background mode to true reduces the Bluetooth scans to happen only once very 5 minutes -- something similar to what iOS does. Based on tests on a Nexus 4, this reduces the phone's overall battery consumption from 95mA to 55mA (both of which numbers include the overall operating system drain.)
Full Disclosure: I work for Radius Networks and am the primary author of the Android iBeaconLibrary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With