【发布时间】:2021-04-06 17:50:26
【问题描述】:
作为主题。我需要获取电脑的本地mac地址,找不到api。
【问题讨论】:
-
@MikePetrichenko “BluetoothAdapter”不是本地设备的 BluetoothAdapter。
-
就是本地蓝牙适配器。
作为主题。我需要获取电脑的本地mac地址,找不到api。
【问题讨论】:
UWP GET我的电脑本地蓝牙mac地址
恐怕你不能用UWP api获取蓝牙电台的mac地址,根据你的要求,我们建议你使用win32 api来获取它,也就是在UWP桌面扩展中调用win32 api。而32feet.NET nuget 可以用来获取蓝牙mac地址。
代码
public static BluetoothAddress GetBTMacAddress()
{
BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;
if (myRadio == null)
{
return null;
}
return myRadio.LocalAddress;
}
我明白了,从 UWP api 获取的 BluetoothAddress 是十进制数。以上是十六进制数,它们是相同的值。我使用以下内容转换为十六进制。感谢@Mike Petrichenko 在下面的评论。
var adapter = await BluetoothAdapter.GetDefaultAsync();
var bleAddress = Convert.ToString(Convert.ToInt64(adapter.BluetoothAddress.ToString()), 16).ToUpper();
【讨论】: