android - 如何使用 altbeacon android 库使用 UUID 搜索信标?

标签 android beacon altbeacon

替代信标库提供了许多基于信标布局的示例。没有关于如何使用 uuid 查找信标的文档?

尝试了代码;

try {
    beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));

    Identifier identifier = Identifier.parse("XXXXXXXX-XXXX-XXXXX-XXXX-XXXXXXXXXXXX"); //beacon 1
    beaconManager.startMonitoringBeaconsInRegion(new Region("identifier", identifier, null, null));
} catch (RemoteException e) {    }

这是行不通的。但是使用 native API 的等效方法工作正常。

List<ScanFilter> scanFilters = new ArrayList<>();
ParcelUuid uid = ParcelUuid.fromString(J_UUID);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(uid).build();
scanFilters.add(filter);

List<ScanFilter> filters = scanFilters;
BluetoothManager bluetoothManager =
                (BluetoothManager) getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
Intent intent = new Intent(getApplicationContext(), MyBroadcastReceiver.class);
intent.putExtra("o-scan", true);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
bluetoothAdapter.getBluetoothLeScanner().startScan(filters, settings, pendingIntent);

感谢任何使用 alt beacon 库实现相同目标的帮助,这样我就不必担心重复安排作业。

最佳答案

不要将 128 位蓝牙 GATT 服务 UUID 与信标的 Proximity UUID 混淆。当用破折号分隔的十六进制数字表示时,两者表面上看起来相似,并且具有相同的字节数,但是两者具有根本不同的目的和将它们与各种 API 一起使用的方式:

Proximity UUID 是一个 BLE 信标概念。它是代表组织对信标所有权的第一个信标标识符,通常用于过滤属于您的信标。它与 iBeacon 和 AltBeacon 格式一起使用(在 AltBeacon 中通常称为 ID1)。该字段编码在 BLE 制造商广告

GATT 服务 UUID 是一个较低级别的 BLE 概念,代表 BLE 外围设备执行的特定功能服务(例如心率监测器)。定制服务通常使用编码在 GATT 服务广告 中的 128 位 GATT 服务 UUID 进行广告,这是与上述制造广告完全不同类型的 BLE 广告数据包。虽然这些服务广告数据包用于 Eddystone 信标,但 Eddystone 格式使用更短的 16 位 GATT 服务 UUID 来宣传自己,并且实际的信标标识符位于其数据有效载荷内。

问题中的第二个代码示例展示了如何使用 Android 的内置 BlE API 查找宣传 128 位 GATT 服务 UUID 的设备。标准信标格式不使用此类结构,这就是为什么 Android 信标库未设计为轻松搜索这些数据包的原因。它是一个专门用于处理 BLE 信标的库,而不是一个更通用的 BLE 库。这就是第一个代码示例不起作用的原因。

标准信标格式不适用于 128 位 GATT 服务 UUID 有几个原因:

  1. 数据包的大小非常有限,128 位 GATT 服务 UUID 占用的空间非常大,几乎没有剩余空间。
  2. 信标格式必须有一个前导码字节模式来标识数据包使用该格式。如果将 128 位 GATT 服务 UUID 用作信标标识符,则在此之前没有可配置的前导码可用于标识信标格式。

一些使用标准格式(如 iBeacon、AltBeacon 或 Eddystone)的信标会交织多个广告,其中一个可能包含 128 位 GATT 服务 UUID,通常用于宣传配置信标的专有服务。如果您有执行此操作的硬件信标,请不要将此广告与实际的信标数据包混淆。此广告应仅用于访问专有配置服务。

关于android - 如何使用 altbeacon android 库使用 UUID 搜索信标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587856/

相关文章:

java - Intent 额外和 Intent 数据之间有什么区别?

android - 未使用 Android 信标库扫描 BLE 设备 CC2541

android - 关于 AltBeacon 的几个问题(一般的 Android 信标技术)

android - 后台iBeacon检查间隔

java - MediaHTTPConnection : readAt 3110239/32768 => java.net.ProtocolException 错误

安卓查短信

android - 如何知道sqlite数据库是否加密

linux - 我们如何从 Linux 中的蓝牙信标(具体估计)获取 RSSI 值?

java - 使用 Beacons-Android 库时 Eddystone 信标不工作

android - 找不到带有 altbeacon 库的信标