使用 android 信标库检测 Eddystone-TLM

use*_*779 2 android altbeacon eddystone beacon

我配置了android 信标库来检测 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);
Run Code Online (Sandbox Code Playgroud)

在 Android 信标库中从未检测到信标。

@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) {
  }
}
Run Code Online (Sandbox Code Playgroud)

测试:

  • 如果信标在 Eddystone-TML 中配置,我可以使用制造商应用程序检测信标遥测数据。
  • 如果信标在 Eddystone-TML 中配置,我无法使用库检测信标。
  • 如果信标在 Eddystone-UID 中配置,我可以使用库和制造商应用程序正确检测信标。

dav*_*ung 5

需要检查两件事以确保您根本没有检测到:

  • 确保onBeaconServiceConnect()被调用。添加一个Log.d声明以确保。
  • 如果您在 Android 6+ 上进行测试,请确保您的应用已获得位置权限。请参阅此处了解更多信息。

编辑:对于 Eddystone-TLM,库没有在测距回调中提供单独的信标实例。该库将这种帧类型视为对主要信标帧(如 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.");

}
Run Code Online (Sandbox Code Playgroud)