You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 02:30:50