'UWP Bluetooth LE FromIdAsync Access is Denied Exception

I am following the code on this page:

https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/gatt-client

It shows simply scanning for devices and then calling FromIdAsync to get the device, but as soon as I call that method I get an exception from the bluetooth dll saying "Access is Denied".

I then found another post when I did a search for FromIdAsync and Access is Denied and it included this code:

        DeviceAccessStatus access = DeviceAccessInformation.CreateFromId(id).CurrentStatus;
        if (access == DeviceAccessStatus.DeniedBySystem || access == DeviceAccessStatus.DeniedByUser)
        {
            Console.WriteLine("Cannot get device permissions");
permissions: {id}");
            return;
        }

So I added this to my app and sure enough it fails the status check.

The app never shows any kind of request for access to the device. The device does not require pairing.

How can I scan for BLE devices in a UWP app without having to pair with it and then connect to it?

I can do this kind of thing on iOS and Android and need to do it on UWP (ultimately HoloLens).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source