我将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库中从未检测到Beacon In。
@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) {
  }
}

测试:
如果在eddystone tml中配置信标,我可以使用制造商应用程序检测信标遥测数据。
如果在eddystone tml中配置信标,则无法使用库检测信标。
如果在eddystone uid中配置了信标,我可以使用library和manufacturer app正确检测信标。

最佳答案

有两件事要检查以确保你根本没有发现:
确保onBeaconServiceConnect()被调用。添加Log.d语句以确保。
如果您正在android 6+上测试,请确保您的应用程序已获得位置权限。更多信息请参见here
编辑:对于eddystone tlm,库在范围回调中不提供单独的Beacon实例。库intead将此帧类型视为主要信标帧的补充,如altbeacon或eddystone uid。因此,如果检测到来自同一设备的另一个主信标帧,它将只提供来自eddystone tlm的信息。
其工作方式是,当检测到像altbeacon或eddystone uid这样的信标帧时,会创建一个Beacon对象并将其传递给测距回调。当检测到eddystone tlm帧来自与主信标帧相同的mac地址时,遥测信息被附加到主信标帧的对象。要访问此信息,请致电:

// 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.");

}

10-05 21:10
查看更多