範圍內的設備是否可以掃描在藍牙範圍內的設備?我嘗試了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藍牙LE InvalidCastException
- 2. 藍牙搜索和接收短信
- 3. Windows 10 UWP與Arduino的藍牙連接
- 4. 藍牙IOException:藍牙關閉
- 5. 如何使用Silverlight在Windows Phone 7中搜索藍牙設備?
- 6. 被動搜索藍牙設備以進行位置檢測
- 7. 通過藍牙搜索可用設備的問題android
- 8. Android藍牙搜索服務可用設備
- 9. 藍牙SPP和其他藍牙服務
- 10. 藍牙和Bleno樹莓藍牙外設
- 11. Android藍牙:RFCOMM +藍牙耳機
- 12. 檢索其通過藍牙的iOS
- 13. 檢索iPhone上的藍牙地址
- 14. 如何使用Android藍牙設備選取器檢索藍牙設備信息?
- 15. Android 6藍牙
- 16. .NET Core藍牙
- 17. 藍牙通訊
- 18. Android藍牙
- 19. GameKit藍牙
- 20. bonjour +藍牙+ iOS
- 21. 遠程藍牙
- 22. 藍牙 - >
- 23. 藍牙配對
- 24. 藍牙插座
- 25. 藍牙通訊
- 26. Android藍牙:IsConnected?
- 27. 通過藍牙
- 28. Xamarin藍牙LE
- 29. 通過藍牙
- 30. Android藍牙PBAP
https://32feet.codeplex.com/ –
你好,問題是,方法返回範圍內或不在範圍內的所有配對設備。我想創建一個藍牙掃描儀來查找範圍內的設備。 – Yoki
一旦藍牙設備與系統配對,設備就被緩存。在此之後,設備將在查詢時自動發現。 AFAIK,我們無法在枚舉設備時獲取當前可用的配對設備。 –