iBeacon background scanning
Asked Answered
I

1

6

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?

Informative answered 9/12, 2013 at 16:10 Comment(0)
R
8

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.

Reptile answered 10/12, 2013 at 3:48 Comment(6)
Hi David, many thx for your comments. For my specific demo I went with the service & the alarm now, but I would totally go with your API otherwise.Informative
I found the IBeacon class and the scanFromRecord method very very helpful. The one thing I cannot understand is what line 216 on is doing. Apparently an estimote beacon is detected but then it would return an "empty" IBeacon class almost. Is this legacy code? I just received iBeacons from estimote and it works. BTW I'd love to get in touch and try your companies beacons and sevices, too. How can we connect directly?Informative
Understood about your demo. this is an open source project so I am always looking for input and collaborators. Perhaps weReptile
... could make it send out a configurable intent when ibeacons are detected. As for your question on line 216, that is for legacy Estimote beacons that did not support the iBeacon profile. The early units they shipped were not strictly iBeacon compatible. For project-specific issues and feature requests, best contact is to open an issue here: github.com/RadiusNetworks/android-ibeacon-service/issues Happy to share my direct email there, too.Reptile
If i kill the application, the service will continue running? Should i do something different to keep the service running after the kill?Epperson
@Otuyh, the library mentioned in this question has been replaced by a more generalized beacon version called the Android Beacon Library here: altbeacon.github.io/android-beacon-library You can read more about how it works when the app has been killed on this page: altbeacon.github.io/android-beacon-library/…Reptile

© 2022 - 2024 — McMap. All rights reserved.