【发布时间】:2020-06-17 10:12:26
【问题描述】:
我正在尝试使用 BLE 在 Android 和 ios 之间实现操作系统间广告和扫描功能。 我需要了解从 Android 设备在 CoreBluetooth 中投放广告需要遵循的流程。 我一直在使用 AltBeacon 库以 iBeacon 格式进行广告,效果很好,但是 ios 无法扫描 iBeacon 上有限数量的信标的限制迫使我转向 CoreBluetooth 框架。
这是我用来以 iBeacon 格式做广告的示例代码:
BluetoothManager bluetoothManager =
(BluetoothManager) applicationContext.getSystemService(Context.BLUETOOTH_SERVICE);
if (bluetoothManager != null) {
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
BluetoothLeAdvertiser mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
if (mBluetoothLeAdvertiser != null) {
beacon = new Beacon.Builder()
.setId1(userId)
.setId2("1")
.setId3("1")
.setManufacturer(0x004C)
.setTxPower(-75)
.setDataFields(Arrays.asList(new Long[]{0l}))
.build();
beaconParser = new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
beaconTransmitter = new BeaconTransmitter(InventaSdk.getContext(), beaconParser);
beaconTransmitter.setBeacon(beacon);
}
}
【问题讨论】:
标签: java android bluetooth-lowenergy core-bluetooth altbeacon