如何在Windows系统中通过.NET获取正确的自定义蓝牙名称?
.NET获取Windows自定义蓝牙名称的解决方案
你当前代码通过BluetoothDevice.FromBluetoothAddressAsync获取的是带MAC地址的默认标识,而非设备管理器中配置的自定义蓝牙名称。问题出在误用了远程蓝牙设备的查询方法来获取本地适配器信息,正确的自定义名称可直接从蓝牙适配器的设备信息中读取。
修正后的代码
using Windows.Devices.Bluetooth; using Windows.Devices.Enumeration; // 获取所有蓝牙适配器的设备信息 var btDevices = await DeviceInformation.FindAllAsync(BluetoothAdapter.GetDeviceSelector()); foreach (var btDevice in btDevices) { // 直接从DeviceInformation读取自定义蓝牙名称 string customBluetoothName = btDevice.Name; // 若需要操作蓝牙适配器实例,同时获取名称 var btAdapter = await BluetoothAdapter.FromIdAsync(btDevice.Id); if (btAdapter != null) { string adapterCustomName = btAdapter.Name; } }
关键说明
DeviceInformation的Name属性直接对应你在设备管理器中配置的自定义蓝牙名称,无需额外创建BluetoothDevice实例。BluetoothAdapter的Name属性也会返回相同的自定义名称,该属性绑定的就是本地蓝牙适配器的配置名称。- 原代码中
BluetoothDevice.FromBluetoothAddressAsync是用于查找远程蓝牙设备的API,并非获取本地适配器信息,因此返回的是系统生成的带地址的默认名称。
内容的提问来源于stack exchange,提问作者user20138168
相关产品推荐
相关产品推荐

