When using RegionBootstrap, and getting a call that you entered a beacon region, I would like to subscribe to an RxJava observable that will begin scanning for particular beacons and possible send up an API call. Is there any reason that BeaconConsumer
must be implemented within a Service or Activity, or can I make a standalone class that implements it, and once it connects, scan for beacons within a region, and unbind when the process has finished?
Asked
Active
Viewed 92 times
0

Nic Capdevila
- 1,495
- 14
- 27
1 Answers
1
A similar question was asked here: onBeaconServiceConnect not called
Basically, the BeaconConsumer interface was designed for a Service or Activity, but you can use it in any kind of class provided you implement all methods and chain them so they make the equivalent calls on some Android context. Whatever class you use, you will need it to hold a reference to an Android context (Activity, Service, Application, etc.) to do this.
@Override
public Context getApplicationContext() {
return context.getApplicationContext();
}
@Override
public void unbindService(ServiceConnection serviceConnection) {
context.unbindService(serviceConnection);
}
@Override
public boolean bindService(Intent intent, ServiceConnection serviceConnection, int i) {
return context.bindService(intent, serviceConnection, i);
}

davidgyoung
- 63,876
- 14
- 121
- 204