I have an UWP project which communicates with a Bluetooth LE device. The communication is working fine but I would like to add one step before establishing the communication which is checking if the Bluetooth is enabled from Windows (10) side:
At the moment, I'm using the class Windows::Devices::Bluetooth::BluetoothAdapter and calling the method getDefaultAsync() to get the actual interface. When I turn if off using the Windows switch, the interface is still there. This is what happens if I turn off the switch:
Here's a snippet of the code:
HANDLE done = CreateEvent(NULL, FALSE, FALSE, NULL);
auto getadapter_op = Windows::Devices::Bluetooth::BluetoothAdapter::GetDefaultAsync();
auto getadapter_optask = create_task(getadapter_op);
getadapter_optask.then([done](Windows::Devices::Bluetooth::BluetoothAdapter^ adapter) {
if (adapter != nullptr)
{
defaultBtInterface = adapter;
}
SetEvent(done);
});
if (WaitForSingleObject(done, 10000) != WAIT_OBJECT_0)
{
}
else
{
}
CloseHandle(done);
if (defaultBtInterface == nullptr) // bluetooth interface is not available
{
printf("Warning: No bluetooth adpter was found\n");
return;
}
The problem is that even if I turn off the switch, the interface is still there. I just get a nullptr if I disable it directly on the Device Manager, like this:
I also tried to use the DeviceInformation.IsEnabled Property but same behavior. Is there some way to check if the Bluetooth Switch is enabled on Windows? Thanks in advance.