question

jeff-4677 avatar image
0 Votes"
jeff-4677 asked vinothkumarmagendiran-0287 published

Windows 10 detect Bluetooth turned off/on

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?

windows-uwp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, can the following method help? Have you solved your issue?

0 Votes 0 ·

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered vinothkumarmagendiran-0287 published

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)
 {
                
 }


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi FayWang-MSFT,



Could you please tell me how to add this Radio class. i don't know how to add this

thanks

0 Votes 0 ·