UWP Bluetooth LE FromIdAsync Access is Denied Exception

Viewed 56

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).

1 Answers

It looks like the issue has something to do with Unity not including the bluetooth capability when building directly from Unity and running.

When I built the project and then loaded it into Visual Studio and executed it there, I did not get any errors.

So that will be my plan....build and then open in Visual Studio.

Related