我正在开发一款可以扫描BLE设备的
Windows手机应用程序.我已经实现了显示所需设备的逻辑.
但问题是,如果我删除这些设备或关闭它们,即使我的应用程序返回扫描结果中的名称.我认为它正在返回缓存结果.我怎样才能确保它只显示那些可用/存在的设备.
我已尝试在扫描中使用其他属性,即System.Devices.Aep.IsPresent等,但无论可用的设备是否可用,它们都会在结果中显示为null.
这是我正在使用的代码片段 –
string[] requestedProperties = new string[] { "System.Devices.Aep.IsPresent","System.Devices.Present","System.Devices.Connected","System.Devices.Paired","System.Devices.Aep.IsConnected","System.Devices.AepContainer.IsPresent" }; diCollection = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(serviceUuid),requestedProperties ); foreach (var diItem in diCollection) { Debug.WriteLine("Discovered Device name - " + diItem.Name); Debug.WriteLine("Discovered Device Additional Properties Below"); foreach (var item in diItem.Properties) { Debug.WriteLine("Key-{0} Value-{1}",item.Key,item.Value); } }
以下是使用的Package.appxmanifest功能 –
<Capabilities> <Capability Name="internetClientServer" /> <DeviceCapability Name="bluetooth" /> </Capabilities>
请帮我解决这个小问题.我在这里错过了一些小事吗?
提前致谢.
-Jitender
解决方法
我尝试使用2台PC下面的每一个属性,其中两台都与手持设备配对,只有一台打开,Windows手持设备8.1.
https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/device-information-properties
需要的是AssociationEndpoint相关的属性,windows phone 8.1中都不支持这些属性(即使枚举不可用) – 所以基本上api没有提供任何方式让我们能够从缓存中查询连接是否是目前是否可用.
我测试了每种组合并且它们没有提供足够的信息(打开的PC与没有打开的PC无法区分).
唯一的解决方法是连接到缓存中的每个配对计算机,并查看每个连接是否成功将其添加到显示的列表中(如果成功).每个失败的连接需要大约4-5秒.因此,如果过去有多台配对计算机,则显示列表可能会有一些大的延迟.然而,我找不到任何其他可行的方法来检查这一点,至少这解决了这个问题.