我配置android beacon library来检测Eddystone数据包
beaconManager = BeaconManager.getInstanceForApplication(context);
// Detect the main identifier (UID) frame:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
// Detect the telemetry (TLM) frame:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15"));
// Detect the URL frame:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v"));
beaconManager.bind(this);
从未在Android信标库中检测到Beacon。
@Override
public void onBeaconServiceConnect() {
beaconManager.addMonitorNotifier(this);
beaconManager.addRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons,
Region region) {
if (beacons.size() > 0) {
Extra.log("Beacons detected", "info");
//Process beacons data...
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region(
"myRangingUniqueId", null, null, null));
} catch (RemoteException e) {
}
}
测试:
答案 0 :(得分:3)
要检查两件事以确保您根本没有检测到:
onBeaconServiceConnect()
。添加Log.d
语句以确定。编辑:对于Eddystone-TLM,库不会在测距回调中提供单独的信标实例。库intead将此帧类型视为补充到主要信标帧,如AltBeacon或Eddystone-UID。因此,如果还检测到来自同一设备的另一个主信标帧,它将仅提供来自Eddystone-TLM的信息。
它的工作方式是当检测到像AltBeacon或Eddystone-UID这样的信标帧时,会创建一个Beacon
对象并将其传递给测距回调。当检测到来自与主信标帧相同的MAC地址的Eddystone-TLM帧时,遥测信息被附加到主信标帧的对象。要访问此信息,请致电:
// Do we have telemetry data?
if (beacon.getExtraDataFields().size() > 0) {
long telemetryVersion = beacon.getExtraDataFields().get(0);
long batteryMilliVolts = beacon.getExtraDataFields().get(1);
long pduCount = beacon.getExtraDataFields().get(3);
long uptime = beacon.getExtraDataFields().get(4);
Log.d(TAG, "The above beacon is sending telemetry version "+telemetryVersion+
", has been up for : "+uptime+" seconds"+
", has a battery level of "+batteryMilliVolts+" mV"+
", and has transmitted "+pduCount+" advertisements.");
}