none
How to know the Bluetooth status on/off from the pc with c# ? RRS feed

  • Question

  • All the ways that I found are for a windows phone that is already dead. So what is the correct way to know if the computer has the Bluetooth on or off with c#?. Windows 7, 8 and 10. Which class should I use ? please an example. Thanks a lot. 
    Tuesday, February 27, 2018 3:38 PM

All replies

  • The CLR does not support Bluetooth.  You can use the C APIs via P/Invoke, but that's tedious.  There are some third-party solutions, like 32feet.net, but nothing from Microsoft directly.

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Tuesday, February 27, 2018 11:52 PM
  • ok thank you so much..

    I forgot to post that I use this: but did not work

    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;
            }
    
            private static async Task<bool> CheckBluetoothEnabled()
            {
                try
                {
                    Windows.Networking.Proximity.PeerFinder.Start();
                    var peers = await Windows.Networking.Proximity.PeerFinder.FindAllPeersAsync();
                    return true;
                }
                catch (Exception ex)
                {
                    if ((uint)ex.HResult == 0x8007048F)
                    {
                        return false;
                    }
                    return true;
                }
            }
    so I will try 32feet.net.

    I already have so much things using:
    using Windows.Devices.Bluetooth;
    using Windows.Devices.Bluetooth.GenericAttributeProfile;

    I hope I will not have problems including that 32feet.net
    Thanks again :). 

    Wednesday, February 28, 2018 1:28 PM
  • Hi Omar,

    Have you solved your issue?

    Since you have using Windows.Devices.Radios, I think your GetBluetoothIsEnabledAsync() method should work. What do you mean by "did not work"? Exception occurs or you get unexpected result?

    Best Regards,

    Charles


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, March 6, 2018 6:45 AM
  • Hey, did you solve this? I have the same issue....
    Thursday, May 23, 2019 10:42 AM
  • Hey, did you solve this? I have the same issue....

    When Bluetooth is OFF, BluetoothFindFirstRadio returns NULL on my Windows 10 OS

    • Edited by Castorix31 Thursday, May 23, 2019 1:56 PM
    Thursday, May 23, 2019 1:52 PM