0

I have the following code which works perfectly on a device with WP8.1 to determine if Bluetooth is enabled or not. When I run it on a Windows Mobile 10 device there is no exception. The app works as expected when Bluetooth is enabled.

private 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; } } 

The project targets WP8.1. How can I get the same behavior on both OS?

2
  • Are you sure it does not throw? Did you put a breakpoint inside the catch? Also I'm not really sure checking for nearby devices is a valid way of checking if bluetooth is enabled... What if you check when no one has a bluetooth device nearby? It would return false even though you have bluetooth on. Commented Mar 10, 2016 at 10:54
  • I did try to set a breakpoint in the catch. I tried it this way because there are some posts I found that use this method to check if it is enabled. Commented Mar 10, 2016 at 11:01

1 Answer 1

2

you can also use a radio class for this.

To check if Bluetooth is enabled:

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; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.