UWP获取我的计算机本地蓝牙mac地址
作为主题。我需要获取计算机的本地mac地址,但找不到api UWP获取我的计算机本地蓝牙mac地址 恐怕您无法使用UWP api获取蓝牙无线电mac地址,根据您的要求,我们建议您使用win32 api获取该地址,换句话说,在UWP桌面扩展中调用win32 api。nuget可以用来获取蓝牙mac地址 代码UWP获取我的计算机本地蓝牙mac地址,uwp,bluetooth,Uwp,Bluetooth,作为主题。我需要获取计算机的本地mac地址,但找不到api UWP获取我的计算机本地蓝牙mac地址 恐怕您无法使用UWP api获取蓝牙无线电mac地址,根据您的要求,我们建议您使用win32 api获取该地址,换句话说,在UWP桌面扩展中调用win32 api。nuget可以用来获取蓝牙mac地址 代码 public static BluetoothAddress GetBTMacAddress() { BluetoothRadio myRadio = BluetoothRadio.
public static BluetoothAddress GetBTMacAddress()
{
BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;
if (myRadio == null)
{
return null;
}
return myRadio.LocalAddress;
}
我知道了,从UWP api得到的蓝牙地址是十进制数。上面是十六进制数,它们是相同的值。我使用以下命令将其转换为十六进制。感谢@Mike Petrichenko在下面的评论
var adapter = await BluetoothAdapter.GetDefaultAsync();
var bleAddress = Convert.ToString(Convert.ToInt64(adapter.BluetoothAddress.ToString()), 16).ToUpper();
@MikePetrichenko“BluetoothAdapter”不是本地设备的BluetoothAdapter。它正是本地BluetoothAdapter。可以使用我上面描述的类(BluetoothAdapter)。当然,这可以通过Win API和Bluetooth框架来完成()我已经更新了案例回复,感谢您的评论。BluetoothAdapter.BluetoothAddress已经是Int64值(ulong),所以它可以非常简单:adapter.BluetoothAddress.ToString(“X12”)(MAC是6字节长,12个十六进制数字)。