如何在UWP中断开蓝牙LE连接

时间:2018-02-26 13:22:29

标签: c# bluetooth uwp bluetooth-lowenergy

我写了一个宣传GATT服务的UWP应用程序。我想知道如何断开连接到我的GATT服务的客户端? 我可以使用DeviceInformation类找到已连接的设备,但调用DisposeSession对象的BluetoothLEDevice方法无效。

string filter = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected);
        DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(filter);

        foreach (DeviceInformation d in devices)
        {
            BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(d.Id);
            var gattServices = await device.GetGattServicesAsync();
            foreach (var service in gattServices.Services)
            {
                if (service.Session.SessionStatus == GattSessionStatus.Active)
                    service.Session.Dispose();

                service.Dispose();
            }
            device.Dispose();
        }

还有其他方法断开客户端设备的蓝牙连接吗?

0 个答案:

没有答案