I am using the Windows::Devices::Bluetooth API to communicate with BLE devices. I would like to detect if Bluetooth is on/off on the PC and also get an event when Bluetooth is turned on/off. Is there an example on how to do this?
I am using the Windows::Devices::Bluetooth API to communicate with BLE devices. I would like to detect if Bluetooth is on/off on the PC and also get an event when Bluetooth is turned on/off. Is there an example on how to do this?
Hello,
Welcome to Microsoft Q&A!
You could try to use Radio class to detect if the Bluetooth is on/off.
public static async Task<bool> GetBluetoothIsEnabledAsync()
{
var radios = await Radio.GetRadiosAsync();
var bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth);
return bluetoothRadio != null && bluetoothRadio.State == RadioState.On;
}
If you want to add a notification event when the Bluetooth is turned on/off, you could subscribe the StateChanged event of bluetoothRadio.
bluetoothRadio.StateChanged += BluetoothRadio_StateChanged;
private static void BluetoothRadio_StateChanged(Radio sender, object args)
{
}
Hi FayWang-MSFT,
Could you please tell me how to add this Radio class. i don't know how to add this
thanks
4 people are following this question.