如何知道win8设备中是否存在蓝牙?

时间:2013-11-27 03:39:34

标签: c# windows-8 bluetooth

我找到了一种使用try PeerFinder.FindAllPeersAsync()

的方法

但我不知道蓝牙硬件是否存在或蓝牙已关闭。

如何区分?

1 个答案:

答案 0 :(得分:1)

根据MSDN,您可以通过检查调用HResult时捕获的异常的PeerFinder.FindAllPeersAsync()来确定蓝牙已关闭。它们提供以下示例代码:

try
{
    var peers = await PeerFinder.FindAllPeersAsync();

    // Handle the result of the FindAllPeersAsync call
}
catch (Exception ex)
{
    if ((uint)ex.HResult == 0x8007048F)
    {
        MessageBox.Show("Bluetooth is turned off");
    }
}

要检测设备功能,请查看PeerFinder.SupportedDiscoveryTypes属性。