Windows 10 detect Bluetooth turned off/on

jeff 1 Reputation point
2020-08-20T20:27:05.447+00:00

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?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Fay Wang - MSFT 5,221 Reputation points
    2020-08-21T02:47:56.9+00:00

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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.