Yes, it is possible to do this, and you do not even need an additional service. The Android iBeacon Library already runs as a service, and it can continue executing in the background simply by binding it to your own extended version of android.app.Application
, which would be responsible for starting ranging for iBeacons. For your use case, you would insert the identifiers of each iBeacon into the database in the didRangeBeaconsInRegion
method.
If you only want the service to start when the user presses a button, simply call a method in your android.app.Application
class to start ranging from your android.app.Activity
class that hosts the button.
You can see the basic setup from the code examples here.
You can do all of this with the open source library, but the Pro version provides additional tools that make it easier to run the service in the background and limit battery usage.