首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AltBeacon库问题

AltBeacon库问题
EN

Stack Overflow用户
提问于 2015-06-22 22:22:44
回答 1查看 1.3K关注 0票数 1

我正在用AltBeacon开发一个安卓项目,在GitHub - https://github.com/justinodwyer/Beacon-Scanner-and-Logger中引用这段代码,但在eclipse中面临以下问题-

代码语言:javascript
复制
The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()

我的代码如下。

代码语言:javascript
复制
BeaconScannerApp app = (BeaconScannerApp)this.getApplication();
beaconManager = app.getBeaconManager();
beaconManager.getBeaconParsers().add(new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
region = new Region("myRangingUniqueId", null, null, null);
beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override 
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        if (beacons.size() > 0) {
        Iterator <Beacon> beaconIterator = beacons.iterator();
        while (beaconIterator.hasNext()) {
        Beacon beacon = beaconIterator.next();
        logBeaconData(beacon);
        }
        }
        }
       });

       try {
           beaconManager.startRangingBeaconsInRegion(region);
       } catch (RemoteException e) {   
        Log.v("TEST", e.getMessage());
       }
EN

回答 1

Stack Overflow用户

发布于 2016-01-28 16:02:34

所有来自信标的初始化都应该在OnBeaconServiceConnect()中进行,我在使用DidExitRegion()和DidEnterRegion()时遇到了麻烦,这正是因为我没有在OnBeaconServiceConnect()中初始化我的BeaconManager处理程序。你也可以,有时,做它的OnCreate,但对我来说是不工作的。它是C#,但它真的很相似。

下面是一个运行良好的示例:

代码语言:javascript
复制
public void OnBeaconServiceConnect()
    {

        beaconManager.SetForegroundScanPeriod(1000L);
        beaconManager.SetForegroundBetweenScanPeriod(10000L);

        rangeNotifier.DidRangeBeaconsInRegionComplete += RangeNotifier_DidRangeBeaconsInRegionComplete;
        monitorNotifier.EnterRegionComplete += MonitorNotifier_EnterRegionComplete;
        monitorNotifier.ExitRegionComplete += MonitorNotifier_ExitRegionComplete;

        beaconManager.SetRangeNotifier(rangeNotifier);
        beaconManager.SetMonitorNotifier(monitorNotifier);

        try
        {
            beaconManager.StartMonitoringBeaconsInRegion(region);
            beaconManager.StartRangingBeaconsInRegion(region);
        }catch(RemoteException e)
        {
            Log.Debug(TAG,e.ToString());
        }

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30982394

复制
相关文章

相似问题

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