服务器收到消息后停止播发

时间:2019-10-11 12:09:01

标签: android bluetooth ads hololens

我正在尝试通过蓝牙从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);

1 个答案:

答案 0 :(得分:0)

当AdvertiseSettings.Builder#setTimeout()将广告时间的值设置为0时,该时间限制将被禁用,除非调用BluetoothLeAdvertiser#stopAdvertising(),否则广告将一直有效。

更多信息,请参见:https://developer.android.com/reference/android/bluetooth/le/AdvertiseSettings.Builder.html#setTimeout(int)