I am developing an android project with AltBeacon referring this code in GitHub - https://github.com/justinodwyer/Beacon-Scanner-and-Logger But facing the following issue in eclipse-
The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()
My code is as follows.
BeaconScannerApp app = (BeaconScannerApp)this.getApplication();
beaconManager = app.getBeaconManager();
beaconManager.getBeaconParsers().add(new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
region = new Region("myRangingUniqueId", null, null, null);
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Iterator <Beacon> beaconIterator = beacons.iterator();
while (beaconIterator.hasNext()) {
Beacon beacon = beaconIterator.next();
logBeaconData(beacon);
}
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
Log.v("TEST", e.getMessage());
}
All the initialization from beacons should be made in OnBeaconServiceConnect() I had a trouble ones with DidExitRegion() and DidEnterRegion() and it was exactly because I was not doing to initialization of my BeaconManager Handlers in OnBeaconServiceConnect(). You can also, sometimes, do it OnCreate but for me was not working. It is C# but it is really similar.
Here it is an example that works well: