ibeacon - How can I start / disable background monitoring for beacons at runtime with AltBeacon Library for Android? -


the altbeacon documentation need initialize library in application oncreate() background monitoring.

but have data needed initialize @ runtime.

specifically @ runtime (after remote http service call) know:

  • if beacon tracking should started @
  • which regions monitor

furthermore may need turn off if condition changes (remotely configured).

what's correct way current version of library (2.5+) handle use case?

when using android beacon library detect beacons in background, construct regionbootstrap class in custom application class described in starting app in background section of samples.

this example shows setting initial region in oncreate method, there no reason needs static in example. welcome execute code call service information whether beacon scanning should started , identifiers should used in region definition. if put after response web service call, move line of code callback:

regionbootstrap = new regionbootstrap(this, region); 

for work custom application class, first parameter still needs reference class. note there alternative constructor class takes list of regions in case want monitor more.

if want change regions monitored @ later time, easiest way calls below:

beaconmanager.getinstanceforapplication(context)     .stopmonitoringbeaconsinregion(oldregion); beaconmanager.getinstanceforapplication(context)     .startmonitoringbeaconsinregion(newregion); 

note possible use above technique initial setup. construct dummy region in application oncreate method instantiating regionbootstrap, , use method calls above configure different ones when callback web service.

note when stopping monitoring of region, need reference region. not need same object -- thing matters stopping monitoring region class' unique identifier. string field used key identify region. in example below, unique identifier "com.example.myapp.boostrapregion".

region region = new region("com.example.myapp.boostrapregion", null, null, null); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -