Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UWP获取我的计算机本地蓝牙mac地址_Uwp_Bluetooth - Fatal编程技术网

UWP获取我的计算机本地蓝牙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.

作为主题。我需要获取计算机的本地mac地址,但找不到api

UWP获取我的计算机本地蓝牙mac地址

恐怕您无法使用UWP api获取蓝牙无线电mac地址,根据您的要求,我们建议您使用win32 api获取该地址,换句话说,在UWP桌面扩展中调用win32 api。nuget可以用来获取蓝牙mac地址

代码

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个十六进制数字)。