13

我正在尝试使用以下 BeaconLayout 检测 Kontakt Beacon:

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

但我似乎没有正确地做到这一点。广告包结构如下:

在此处输入图像描述

提前致谢。

4

2 回答 2

15

感谢@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) {   }
}

请注意,我使用的是 2.2 版本的 Kontakt 信标,它与上面发布的布局不同。

于 2014-08-17T19:51:25.280 回答
6

A few issues with your 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.

  2. The table shows there are only three identifiers in the beacon, but your beaconLayout string has four. Note the first identifier is 16 bytes long.

If you get it working, please post the correct beaconLayout you used.

于 2014-08-15T21:09:40.257 回答