如何查看广告商已连接

How to view that Advertiser is connected

我要以广告商的身份查看它是否已连接到中央设备。

我查看了以前的问题,并根据 Microsoft 文档中的所有内容进行了设计:https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.genericattributeprofile.gattcommunicationstatus。然而,他们通过设计使广告商无法在没有任何类型的 read/write/notify 操作的情况下查看其是否已连接。我想知道是否有人对此有任何解决方法?

       GattServiceProviderAdvertisingParameters advParameters = new GattServiceProviderAdvertisingParameters
        {
            // IsConnectable determines whether a call to publish will attempt to start advertising and 
            // put the service UUID in the ADV packet (best effort)
            IsConnectable = peripheralSupported,

            // IsDiscoverable determines whether a remote device can query the local device for support 
            // of this service
            IsDiscoverable = true,
            ServiceData = buffer
        };

我想查看 "IsConnectable" 但是我无法查看。

谢谢,

我想通了,这是我的解决方案,以防其他人遇到此问题。 WM_DeviceChange 评论为我指明了正确的方向。 最终我遇到了:

DeviceInformationCollection ConnectedBluetoothDevices =
               await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));

我能够使用的是:

 public static async void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
        DeviceInformationCollection ConnectedBluetoothDevices =
               await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));
        if(ConnectedBluetoothDevices.Count != 0)
        {
            Console.WriteLine("New Device Found.");
        } 
    }

我基本上在定时事件中进行了检查,以查看连接的 BLE 设备是否增加,如果是,我向控制台写了一条消息。

定时器见:What is the best way to implement a "timer"?

我从这里得到了 BLE 设备代码列表: