我使用AltBeacon库来检测iBeacon设备。这是我使用的代码,基于AltBeacon的文档,但没有检测到信标:使用Android上的AltBeacon库检测iBeacon
beaconManager = BeaconManager.getInstanceForApplication(this);
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);
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.i("test", "I just saw an beacon for the first time!");
}
@Override
public void didExitRegion(Region region) {
Log.i("test", "I no longer see an beacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i("test", "I have just switched from seeing/not seeing beacons: "+state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("e2c56db5-dffb-48d2-b060-d0f5a71096e0", null, null, null));
} catch (RemoteException e) { }
这段代码错了吗?
我的活动实际上实现了BeaconConsumer事实上的代码编译没有问题。 现在我已经修改了代码: 'beaconManager.startMonitoringBeaconsInRegion(新区域( “com.example.app.region1”, Identifier.parse( “e2c56db5-dffb-48d2-B060-d0f5a71096e0”),空, null));' 但仍然无法正常工作。 另外我已经在try/catch块中添加了一个日志,并且代码没有失败。任何解决方案 – Loris
此外,当我第一次启动应用程序时,事件'didDetermineStateForRegion'被触发,状态参数为0 – Loris
您是否获得了onBeaconServiceConnected的回调? – davidgyoung