Android 使用AltBeacon库以Gatt服务UUID格式扫描和公布
我已经编写了一段代码来在GattService UUID中进行广告,尽管我仍然无法确定应该运行哪种解析器来只接受以相同格式进行广告的结果,这是一种有效的广告模式 在Gatt服务UUID中发布的代码:Android 使用AltBeacon库以Gatt服务UUID格式扫描和公布,android,bluetooth,bluetooth-lowenergy,altbeacon,Android,Bluetooth,Bluetooth Lowenergy,Altbeacon,我已经编写了一段代码来在GattService UUID中进行广告,尽管我仍然无法确定应该运行哪种解析器来只接受以相同格式进行广告的结果,这是一种有效的广告模式 在Gatt服务UUID中发布的代码: public void startGattServiceAdvertising() { BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter(); if (defaultAdapter == null
public void startGattServiceAdvertising() {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
if (defaultAdapter == null) {
return;
}
String uniqueId = "Hello world";
if (uniqueId.isEmpty()) {
return;
}
defaultAdapter.setName(uniqueId);
BluetoothLeAdvertiser advertiser = defaultAdapter.getBluetoothLeAdvertiser();
AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_LOW)
.setConnectable(true);
String userId = "4539c428-0c3c-4606-b701-98bde9c39a82";
ParcelUuid pUuid = new ParcelUuid(UUID.fromString(userId));
LogHelper.d("Parcel: ", "UUID: " + pUuid.getUuid());
AdvertiseData data = new AdvertiseData.Builder()
.setIncludeDeviceName(false)
.addServiceUuid(pUuid)
.setIncludeTxPowerLevel(false).build();
LogHelper.d("Parcel: ", "Service UUID: " + data.getServiceUuids().toString());
if (advertiser != null) {
try {
advertiser.startAdvertising(settingsBuilder.build(), data, getAdvertiseCallback());
} catch (Exception e) {
e.printStackTrace();
// Adding common exception just to retry this if anything goes wrong in the first time
// (Chinese devices facing some legacy data issue)
//Some OEM shows Advertising data too large exception,so not sending txPowerLevel
}
}
}
这与我正在寻找的方式完全一样,我也能够在其他设备上检测到同样的情况,我唯一关心的是我需要在库端进行更改以验证此特定格式,就像AltBeacon库通过调用
fromScanData(…)
方法对其他格式所做的那样。我是否需要公布一些额外的信息,或者在扫描端应该进行哪些更改,以便我通过解析器成功运行检测到的信标。显示的代码只是发出一个标准的BLE 128位服务UUID公告,该公告恰好在服务UUID字段中放置了一个用户id
这很好——但它无法让您在接收端确定这是“您的”广告,还是不是源于硬件设备的广告。例如,苹果手表将发出一个使用相同格式的特定128位服务UUID。因此,如果你的Android应用程序扫描这则广告时遇到苹果手表,它会认为这是一个特定的用户id
像iBeacon、AltBeacon和Eddystone这样的标准信标格式至少有三个部分,第一个部分解决了这个问题:
如果需要iOS互操作性,请注意使用服务广告。虽然iOS可以扫描和传输这些广告,但它不能在后台传输这种格式。此外,它根本无法附加服务数据,这使得上述第(1)点不可能实现。出于同样的原因,Eddystone格式根本无法在iOS上发布。是。有道理。因此,基于这一解释,我不可能找到一种变通方法来检测这是否是我所期望的信标之一?只有Android的方法,但是没有一个可以用于iOS的发送和接收。你能分享一些资源让我四处看看只有Android的方式吗?Eddystone UID是一个类似的服务广告,你只能在Android上发送,也可以在两个平台上接收:。传送: