如何查看广告商是否已连接

我将以广告客户的身份查看是否已将其连接到中央设备。

我已经根据microsoft文档上的所有内容查看了以前的问题和设计:https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.genericattributeprofile.gattcommunicationstatus。但是,他们的目的是使广告客户在没有任何类型的读/写/通知操作的情况下无法查看其是否已连接。我想知道是否有人对此有任何解决方法?

       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”,但是我无法查看。

谢谢

tongfang001 回答:如何查看广告商是否已连接

我已经弄清楚了,这是我的解决方案,以防其他人遇到此问题。 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设备代码列表: Getting a list of already connected bluetooth devices on Windows 10

本文链接:https://www.f2er.com/3150113.html

大家都在问