首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓AltBeacon测距

安卓AltBeacon测距
EN

Stack Overflow用户
提问于 2016-02-01 13:30:51
回答 1查看 584关注 0票数 2

我想扫描我周围的任何一种信标。基本上,如果我理解正确的话,你需要在扫描之前知道他们的身份?你如何扫描你周围的任何信标,提取它们的UUID/工厂Id/等等?

以下是我的当前代码:

代码语言:javascript
复制
public class TestActivity extends Activity implements BeaconConsumer {

private BeaconManager beaconManager;

public static final String TAG = "TestActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startBeaconScan();
}

public void startBeaconScan() {
    beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager.setDebug(true);
    beaconManager.bind(this);
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
    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"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.setMonitorNotifier(new MonitorNotifier() {
        @Override
        public void didEnterRegion(final Region region) {
            Log.d(TAG, "ENTERED REGION: "+region);
        }

        @Override
        public void didExitRegion(Region region) {}

        @Override
        public void didDetermineStateForRegion(int i, Region region) {}
    });
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
            Log.d(TAG, "BEACONS: "+collection.size());
        }
    });
}

@Override
public void onBeaconServiceConnect() {
    try {
        beaconManager.startMonitoringBeaconsInRegion(new Region("myRegion", null, null, null));
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

}

我在输出中得到这些消息,但没有其他消息:

代码语言:javascript
复制
beacon detected : id1: f7826da5-4fa1-4e48-8024-bc5b70e0891a id2: 49089 id3: 34388

所以问题是,我如何在不事先知道身份的情况下探测到这些信标?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-01 13:56:39

两点:

  1. 创建一个具有所有空标识符的Region定义本质上是一个通配符,它将匹配所有信标标识符,因此您不需要预先了解它们。所显示的代码已经有了以下内容。
  2. 要得到探测到的信标列表,您需要开始测距。显示的代码有一个令人愤怒的回调,但它没有启动范围。

在这一行之后:

代码语言:javascript
复制
beaconManager.startRangingBeaconsInRegion(new Region("myRegion", null, null, null));

添加以下内容:

代码语言:javascript
复制
beaconManager.startMonitoringBeaconsInRegion(new Region("myRegion", null, null, null));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35131806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档