AltBeacon 库问题
AltBeacon Library issue
我正在使用 AltBeacon 开发一个 android 项目,在 GitHub - https://github.com/justinodwyer/Beacon-Scanner-and-Logger 中引用此代码
但在 eclipse-
中面临以下问题
The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()
我的代码如下
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());
}
信标的所有初始化都应该在 OnBeaconServiceConnect() 中进行 我在使用 DidExitRegion() 和 DidEnterRegion() 时遇到了麻烦,这正是因为我没有在 OnBeaconServiceConnect() 中初始化我的 BeaconManager 处理程序。有时,您也可以在 OnCreate 上执行此操作,但对我来说不起作用。是C#,但是真的很像。
这是一个运行良好的示例:
public void OnBeaconServiceConnect()
{
beaconManager.SetForegroundScanPeriod(1000L);
beaconManager.SetForegroundBetweenScanPeriod(10000L);
rangeNotifier.DidRangeBeaconsInRegionComplete += RangeNotifier_DidRangeBeaconsInRegionComplete;
monitorNotifier.EnterRegionComplete += MonitorNotifier_EnterRegionComplete;
monitorNotifier.ExitRegionComplete += MonitorNotifier_ExitRegionComplete;
beaconManager.SetRangeNotifier(rangeNotifier);
beaconManager.SetMonitorNotifier(monitorNotifier);
try
{
beaconManager.StartMonitoringBeaconsInRegion(region);
beaconManager.StartRangingBeaconsInRegion(region);
}catch(RemoteException e)
{
Log.Debug(TAG,e.ToString());
}
}
我正在使用 AltBeacon 开发一个 android 项目,在 GitHub - https://github.com/justinodwyer/Beacon-Scanner-and-Logger 中引用此代码 但在 eclipse-
中面临以下问题The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()
我的代码如下
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());
}
信标的所有初始化都应该在 OnBeaconServiceConnect() 中进行 我在使用 DidExitRegion() 和 DidEnterRegion() 时遇到了麻烦,这正是因为我没有在 OnBeaconServiceConnect() 中初始化我的 BeaconManager 处理程序。有时,您也可以在 OnCreate 上执行此操作,但对我来说不起作用。是C#,但是真的很像。
这是一个运行良好的示例:
public void OnBeaconServiceConnect()
{
beaconManager.SetForegroundScanPeriod(1000L);
beaconManager.SetForegroundBetweenScanPeriod(10000L);
rangeNotifier.DidRangeBeaconsInRegionComplete += RangeNotifier_DidRangeBeaconsInRegionComplete;
monitorNotifier.EnterRegionComplete += MonitorNotifier_EnterRegionComplete;
monitorNotifier.ExitRegionComplete += MonitorNotifier_ExitRegionComplete;
beaconManager.SetRangeNotifier(rangeNotifier);
beaconManager.SetMonitorNotifier(monitorNotifier);
try
{
beaconManager.StartMonitoringBeaconsInRegion(region);
beaconManager.StartRangingBeaconsInRegion(region);
}catch(RemoteException e)
{
Log.Debug(TAG,e.ToString());
}
}