范围内的设备是否可以扫描在蓝牙范围内的设备?我尝试了FindAll方法,但它返回所有配对的设备。也试过了deviceWatcher,结果相同。搜索蓝牙UWP
搜索蓝牙UWP
回答
是否可以扫描在蓝牙范围内的设备?
这是可能的,我们可以使用DeviceInformation.FindAllAsync方法或DeviceWatcher类。但要获得所有蓝牙设备,我们需要注意的是,当前的蓝牙API不提供选择器来获得所有已配对和未配对的设备。 BluetoothDevice.GetDeviceSelector方法实际返回的值与BluetoothDevice.GetDeviceSelectorFromPairingState(true)相同。因此,当您使用此选择器(高级查询语法(AQS)字符串)时,您将始终获得所有配对的设备。
要获得所有的设备,我们可以用这个选择会首先配对的设备,然后使用BluetoothDevice.GetDeviceSelectorFromPairingState(false)
获得其余未配对设备。
或者我们可以指定AQS字符串类似如下:
//The AQS string for getting all Bluetooth devices
var BluetoothDeviceSelector = "System.Devices.DevObjectType:=5 AND System.Devices.Aep.ProtocolId:=\"{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}\"";
//Using DeviceInformation.FindAllAsync method
var deviceInfoCollection = await DeviceInformation.FindAllAsync(BluetoothDeviceSelector);
//Using DeviceWatcher class
var deviceWatcher = DeviceInformation.CreateWatcher(BluetoothDeviceSelector);
PS:FindAllAsync方法,多用通过当前连接或与系统配对的设备看。要获得配对和非配对设备,最好使用DeviceWatcher类。
有关如何使用FindAllAsync方法或DeviceWatcher类的更多信息,请参阅Enumerate devices和官方Device enumeration and pairing sample。
此外Bluetooth devices,也有Bluetooth LE devices你可能会想。而对于蓝牙LE设备,AQS字符串将是System.Devices.DevObjectType:=5 AND System.Devices.Aep.ProtocolId:="{BB7BB05E-5972-42B5-94FC-76EAA7084D49}"
。
周杰伦,我试图做的一样你所描述的,但保持有一个问题 - 为配对设备,我无法理解一个设备是否真的可用 - 在最初扫描System.Devices.Aep.IsPresent被返回true,只有连接尝试失败后将变为false。我该怎么办?甚至System.Devices.Aep.SignalStrength也显示了设备的缓存值在几周内还没有看到。 –
我提供了下面的代码BluetoothLE设备选择字符串。这个对我有用。
DeviceWatcher dWatcher = null;
var BluetoothDeviceSelector = "System.Devices.DevObjectType:=5 AND System.Devices.Aep.ProtocolId:=\"{BB7BB05E-5972-42B5-94FC-76EAA7084D49}\" AND ((System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#True OR System.Devices.Aep.IsPaired:=System.StructuredQueryType.Boolean#False) OR System.Devices.Aep.Bluetooth.IssueInquiry:=System.StructuredQueryType.Boolean#False)";
dWatcher = DeviceInformation.CreateWatcher(BluetoothDeviceSelector);
dWatcher.Added += DeviceAdded;
dWatcher.Updated += DeviceUpdated;
dWatcher.Start();
- 1. UWP蓝牙RFCOMM FindAllAsync
- 2. UWP蓝牙LE InvalidCastException
- 3. Android搜索蓝牙设备
- 4. 安卓:Wifi和蓝牙搜索一起
- 5. 蓝牙搜索和接收短信
- 6. Windows 8.1蓝牙搜索问题
- 7. Windows 10 UWP与Arduino的蓝牙连接
- 8. 索尼Smartwatch 2蓝牙API
- 9. 蓝牙IOException:蓝牙关闭
- 10. 被动搜索蓝牙设备以进行位置检测
- 11. 搜索蓝牙设备和使用android编程显示
- 12. Android蓝牙搜索服务可用设备
- 13. 如何在ionic2纹波蓝牙搜索中创建设计
- 14. 蓝牙低功耗Android - 在后台搜索
- 15. 如何使用Silverlight在Windows Phone 7中搜索蓝牙设备?
- 16. 如何搜索未配对的蓝牙设备?
- 17. 通过蓝牙搜索可用设备的问题android
- 18. Android蓝牙:RFCOMM +蓝牙耳机
- 19. 蓝牙和Bleno树莓蓝牙外设
- 20. 蓝牙SPP和其他蓝牙服务
- 21. Android蓝牙LE和经典蓝牙API
- 22. 蓝牙不搜索新设备/如何通过蓝牙发送字符串消息?
- 23. 在蓝牙设备搜索过程中将obd扫描工具与其他蓝牙设备隔离
- 24. simultanously在物联网核心使用多个蓝牙HCI UWP
- 25. UWP蓝牙ConnectAsync错误到Raspberry Pi。元素未找到
- 26. UWP蓝牙低功耗应用早期断开连接
- 27. UWP应用程序中蓝牙连接的通知
- 28. 检索iPhone上的蓝牙地址
- 29. 检索其通过蓝牙的iOS
- 30. 如何使用Android蓝牙设备选取器检索蓝牙设备信息?
https://32feet.codeplex.com/ –
你好,问题是,方法返回范围内或不在范围内的所有配对设备。我想创建一个蓝牙扫描仪来查找范围内的设备。 – Yoki
一旦蓝牙设备与系统配对,设备就被缓存。在此之后,设备将在查询时自动发现。 AFAIK,我们无法在枚举设备时获取当前可用的配对设备。 –