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?
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;
}
User contributions licensed under CC BY-SA 3.0