简体   繁体   English

使用AltBeacon在Android上检测Kontakt Beacon的正确布局

[英]Correct layout to detect Kontakt Beacon on Android with AltBeacon

I'm trying to detect a Kontakt Beacon with the following BeaconLayout: 我正在尝试使用以下BeaconLayout检测Kontakt Beacon:

setBeaconLayout("m:8-9=0215,i:10-13,i:14-15,i:16-17,i:18-25"));

but I don't seem to be doing it correctly. 但我似乎没有正确地做到这一点。 The advertising packet structure is like this: 广告包结构如下:

在此输入图像描述

Thanks in advance. 提前致谢。

Thanks to @davidgyoung comments, I finally could detect my Kontakt beacon with the following code: 感谢@davidgyoung评论,我终于可以使用以下代码检测我的Kontakt信标:

public class MainActivity extends Activity implements BeaconConsumer {

protected static final String TAG = "RangingActivity";
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);        
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.bind(this);    
}

@Override
public void onBeaconServiceConnect() {
      beaconManager.setRangeNotifier(new RangeNotifier() {
            @Override 
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                if (beacons.size() > 0) {
                    Log.d(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");     
                }
            }
            });

            try {
                beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
            } catch (RemoteException e) {   }
}

Please note that I'm using a 2.2 version Kontakt beacon, which is a different version from the layout posted above. 请注意,我使用的是2.2版Kontakt信标,它与上面发布的版面不同。

A few issues with your beaconLayout: 您的beaconLayout存在一些问题:

  1. The byte offsets in the beaconLayout string start with the manufacturer data (byte 6 in the table you show) so you need to subtract 6 from all of your offsets. beaconLayout字符串中的字节偏移量以制造商数据(您显示的表中的字节6)开头,因此您需要从所有偏移量中减去6。

  2. The table shows there are only three identifiers in the beacon, but your beaconLayout string has four. 该表显示信标中只有三个标识符,但beaconLayout字符串有四个。 Note the first identifier is 16 bytes long. 注意,第一个标识符长度为16个字节。

If you get it working, please post the correct beaconLayout you used. 如果你使用它,请发布你使用的正确beaconLayout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM