我正在尝试使用DevicePicker
在我的VB.NET UWP应用程序中启用蓝牙设备配对。当我运行此代码时,设备选择器甚至不会尝试搜索蓝牙设备,而是立即建议我“确保设备已打开且可被发现”。在设置中可以发现和配对蓝牙设备。我是否需要以某种方式为我的UWP应用程序启用/激活蓝牙? (我正在尝试与Windows PC上的iPhone配对并与之交互。)
我的代码如下:
Imports Windows.Devices.Bluetooth
Imports Windows.Devices.Enumeration
Public NotInheritable Class MainPage
Inherits Page
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
Debug.WriteLine("Starting enumeration...")
Dim dp = New DevicePicker()
dp.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelector())
dp.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(False))
dp.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(True))
Dim mydev As DeviceInformation = Await dp.PickSingleDeviceAsync(New Rect())
If mydev IsNot Nothing Then
Await mydev.Pairing.PairAsync(DevicePairingProtectionLevel.EncryptionAndAuthentication)
End If
End Sub
End Class
谢谢!