服务器收到消息后停止广告
Stop advertising after Server received message
我正在尝试通过蓝牙从 android 设备向 hololens 发送一个简单的字符串。
我已经完成了这个,但是 android 设备在调用 startAdvertising();
之后不断地将字符串发送到服务器
BluetoothAdapter mBluetoothAdapter;
BluetoothLeAdvertiser mBLEAdvertiser;
private void startAdvertising(int manufactureId, byte[] manufactureData) throws InterruptedException {
if (mBLEAdvertiser == null) return;
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
.setConnectable(false)
.setTimeout(0)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
.build();
AdvertiseData data = new AdvertiseData.Builder()
.addManufacturerData(manufactureId, manufactureData)
.build();
mBLEAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
当AdvertiseSettings.Builder#setTimeout()将广告时间的值设置为0时,时间限制将被禁用,广告一直有效,除非调用BluetoothLeAdvertiser#stopAdvertising()。
我正在尝试通过蓝牙从 android 设备向 hololens 发送一个简单的字符串。
我已经完成了这个,但是 android 设备在调用 startAdvertising();
BluetoothAdapter mBluetoothAdapter;
BluetoothLeAdvertiser mBLEAdvertiser;
private void startAdvertising(int manufactureId, byte[] manufactureData) throws InterruptedException {
if (mBLEAdvertiser == null) return;
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
.setConnectable(false)
.setTimeout(0)
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
.build();
AdvertiseData data = new AdvertiseData.Builder()
.addManufacturerData(manufactureId, manufactureData)
.build();
mBLEAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
当AdvertiseSettings.Builder#setTimeout()将广告时间的值设置为0时,时间限制将被禁用,广告一直有效,除非调用BluetoothLeAdvertiser#stopAdvertising()。