【发布时间】:2020-09-28 17:43:00
【问题描述】:
我有一台客户的笔记本电脑无法连接到蓝牙打印机。这是一个经典,适用于我的机器(和其他几个)情况。我有一种感觉,它是一种安全许可、防病毒等,我只是想证明它或找到安全设置以使其工作或重写我的代码来处理这种情况。 ——你知道解决问题。
打印机确实与笔记本电脑配对没有任何问题(打印配对密钥),但是当我尝试从 Id 中找到它时,它总是返回 null:
var bluetoothDevice = await BluetoothDevice.FromIdAsync(device.Id) //bluetoothDevice = null
我尝试了BluetoothDevice 和BluetoothLeDevice API,没有运气。
我使用了 Microsoft 的示例 GATT services,得到了相同的结果。无法连接到笔记本电脑上的设备,在我的开发机器上工作正常。
我添加了 DeviceAccessInformation API 来获取当前状态并返回:
Windows.Devices.Enumeration.DeviceAccessStatus.DeniedByUser
//on my dev machine I get DeviceAccessStatus.Allowed
我在 DeviceAccessInformation API 上找不到任何可以告诉我为什么/如何返回 DeniedByUser 的信息。
一如既往,感谢您抽出宝贵时间。
Windows 版本:1909 (18363.78)
适用代码:
var devices = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector());
foreach (var device in devices)
{
var accessStatus = DeviceAccessInformation.CreateFromId(device.Id).CurrentStatus;
textLog.AppendLine($"---DeviceId: {device.Id} -- {accessStatus}");
using (var bluetoothDevice = await BluetoothDevice.FromIdAsync(device.Id))
{
if (bluetoothDevice == null)
{
textLog.AppendLine($"---DeviceId: {device.Id} Not Found");
textLog.AppendLine($"---Device Information: {JsonConvert.SerializeObject(device)}");
txtLog.Text = textLog.ToString();
continue;
}
}
}
远程笔记本电脑日志输出:
connecting to ac:3f:a4:dd:69:a7
---DeviceId: Bluetooth#Bluetoothac:67:5d:1d:d5:25-ac:3f:a4:dd:69:a7 -- DeniedByUser
---DeviceId: Bluetooth#Bluetoothac:67:5d:1d:d5:25-ac:3f:a4:dd:69:a7 Not Found
---Device Information: {"EnclosureLocation":null,"Id":"Bluetooth#Bluetoothac:67:5d:1d:d5:25-ac:3f:a4:dd:69:a7","IsDefault":false,"IsEnabled":false,"Name":"dev-zebra1","Properties":{},"Kind":5,"Pairing":{"CanPair":false,"IsPaired":false,"Custom":{},"ProtectionLevel":1}}
---Printer [ac:3f:a4:dd:69:a7] not found
我的开发机器日志输出:
connecting to ac:3f:a4:dd:69:a7
---DeviceId: Bluetooth#Bluetooth00:23:15:d4:a2:e1-ac:3f:a4:dd:69:a7 -- Allowed
---Device Information: {"EnclosureLocation":null,"Id":"Bluetooth#Bluetooth00:23:15:d4:a2:e1-ac:3f:a4:dd:69:a7","IsDefault":false,"IsEnabled":false,"Name":"dev-zebra1","Properties":{},"Kind":5,"Pairing":{"CanPair":false,"IsPaired":false,"Custom":{},"ProtectionLevel":1}}
--- 更新 ---
我已经根据 David 提供的链接设置了功能。我厌倦了将所有功能类型放在那里,但笔记本电脑上没有任何变化。我添加了网络摄像头功能,我看到切换显示在应用权限下。但我从来没有看到蓝牙开关。
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="bluetooth"/>
<DeviceCapability Name="webcam"/>
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type ="name:serialPort"/>
</Device>
</DeviceCapability>
</Capabilities>
【问题讨论】:
标签: windows uwp bluetooth bluetooth-lowenergy