我想检查设备上是否启用了蓝牙(以便应用程序可以在没有用户交互的情况下使用它)。有什么办法可以做到这一点吗?我还可以分别检查蓝牙和蓝牙低功耗吗?
我使用以下方法完成了此操作Radio
class.
检查蓝牙是否已启用:
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;
}
要检查是否支持蓝牙(一般情况下):
public static async Task<bool> GetBluetoothIsSupportedAsync()
{
var radios = await Radio.GetRadiosAsync();
return radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth) != null;
}
如果未安装蓝牙,则无线电列表中将没有蓝牙无线电,并且那里的 LINQ 查询将返回 null。
至于分别检查蓝牙经典和LE,我目前正在研究实现这一点的方法,并且当我确定有一种方法存在并且有效时,我会更新这个答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)