1

I am attempting to use a DevicePicker to enable pairing of Bluetooth devices in my VB.NET UWP application. When I run this code, the device picker doesn't even attempt to search for Bluetooth devices and immediately advises me to "Make sure the device is turned on and discoverable." Discovering and pairing Bluetooth devices works in Settings. Do I need to somehow enable/activate Bluetooth for my UWP application? (I am trying to pair and interact with an iPhone from a Windows PC.)

The code I have is below:

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

Thanks!

user9811991
  • 317
  • 5
  • 14
  • 1
    Thanks! Adding the Bluetooth capability does not seem to work; still no devices are discovered. Instead, I can try to advertise support for a GATT characteristic. How would I advertise support for a GATT characteristic with specific UUIDs? @NicoZhu-MSFT – user9811991 Jul 10 '19 at 19:11
  • 1
    I tried to make my device discoverable on iOS, but that wasn't entirely working either. [I asked a new question about it.](https://stackoverflow.com/questions/56981438/make-uwp-app-discoverable-in-ios-bluetooth-settings) – user9811991 Jul 11 '19 at 04:16
  • 1
    For watching Bluetooth devide(not BLE) Please refer this code [sample](https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/DeviceEnumerationAndPairing/cs/Scenario2_DeviceWatcher.xaml.cs#L19). And before use it please enable Bluetooth capability. – Nico Zhu Jul 12 '19 at 10:07

0 Answers0