检测灯塔退出的范围 [英] Detect beacon exited a range

查看:418
本文介绍了检测灯塔退出的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Android编写的 AltBeacon 库。
我开始开发一个应用程序BLE应该告诉我,当一个信标进入,当它正在退出的区域内一系列这样我就可以开始操作。

I am using Android with the AltBeacon library. I am starting to develop a BLE app which should tell me when a beacon is entering and when it is exiting a range inside a region so I can start an action.

当一个信标进入一个区域,我可以检测并确定他的范围。因此,我使用了 didRangeBeaconsInRegion 方法。

I could detect when a beacon is entering a region and determine his range. Therefore I used the didRangeBeaconsInRegion Method.

我现在的问题是如何检测到信标已经离开/退出在该地区的范围是多少?我找不到在lib任何这样做的。

My problem is now how to detect that a beacon has left/exited that range in the region? I couldn't find anything in the lib to do so.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

借助 Android的灯塔库为寻找信标台的API提供:

The Android Beacon Library offers to sets of APIs for looking for beacons:


  1. 测距的API。这给你一个回调 didRangeBeaconsInRegion 大约每秒钟所关注的信标在范围内,并提供所有这些信标列表,以便您可以检查它们的标识符。

  1. Ranging APIs. These give you a callback to didRangeBeaconsInRegion approximately every second that beacons of interest are in range, and provides a list of all these beacons so you can inspect their identifiers.

监视API。这些提供了回调,只有当利益出现标 didEnterRegion 或消失 didExitRegion

Monitoring APIs. These provide callbacks only when beacons of interest appear didEnterRegion or disappear didExitRegion.

您的问题表明,当前已实施的测距的API,并需要实施监控API知道什么时候所有感兴趣的信标消失。

Your question suggests that you have currently implemented the Ranging APIs, and need to implement the Monitoring APIs to know when all beacons of interest disappear.

您可以看到在监控范例code这样的一个例子在本页面的顶部。

You can see an example of this in the Monitoring Example Code section at the top of this page.

修改:请注意,您可以监视根据个人的信标区域,动态地改变正在被监视。所以在回调不等,你可以这样做:

EDIT: Note that you can monitor regions based on individual beacons and dynamically change which are being monitored. So in the ranging callback you could do something like:

Region singleBeaconRegion = new Region(beacon.toString(), beacon.getIdentifiers());
beaconManager.startMonitoringBeaconsInRegion(singleBeaconRegion);

这将启动监视单个航标匹配传入标识符。你会得到一个回调 didExitRegion 当它不再可见。

This will start monitoring for a single beacon matching the passed identifiers. You will get a callback to didExitRegion when it is no longer visible.

如果你使用这个技术,你也应该停止监视退出该地区,所以你的监控区域列表中没有大的增长在一段时间:

If you use this technique, you should also stop monitoring the region on exit, so your monitored region list does not grow large over time:

public void didExitRegion(Region region) {
    // perform logic based on region here
    beaconManager.stopMonitoringBeaconsInRegion(region);
}

这篇关于检测灯塔退出的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆