我有以下代码,可以在具有WP8.1的设备上完美运行,以确定是否启用了蓝牙。当我在Windows Mobile 10设备上运行它时,没有例外。启用蓝牙后,该应用程序按预期工作。
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;
}
}
该项目的目标是WP8.1。如何在两个操作系统上获得相同的行为?
答案 0 :(得分:2)
你也可以使用无线电课程。
检查蓝牙是否已启用:
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;
}