在Windows10 UWP查找蓝牙的Mac地址,而配对 [英] Finding Bluetooth Mac address in Windows10 UWP without pairing

查看:4617
本文介绍了在Windows10 UWP查找蓝牙的Mac地址,而配对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个应用程序,读取所有MAC在Windows 10物联网解决各地。 code的这些线路将返回所有配对设备,即使它们无法开启。

I'm trying to write an app that reads all MAC addresses around on Windows 10 IoT. These lines of code is returning all paired devices even if they aren't turn on.

var selector = BluetoothDevice.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(selector);
listBox.Items.Add(devices.Count);
foreach (var device in devices)
{
    listBox.Items.Add(device.Id);
}

和我也发现了这条线code的

And I also found this line of code

await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

这返回null虽然。有什么办法在Windows 10通用的应用程序扫描所有MAC地址的?

This returning null though. Is there any way to scan for all MAC addresses in a Windows 10 universal app?

推荐答案

有是采用新的方法<一href=\"https://msdn.microsoft.com/en-us/library/windows.devices.bluetooth.advertisement.bluetoothleadvertisementwatcher.aspx\"相对=nofollow> BluetoothLEAdvertisementWatcher 扫描所有蓝牙LE设备周围。
这里是一块code的我在我的项目是:

There is a new approach using BluetoothLEAdvertisementWatcher to scan for all Bluetooth LE device around. Here is a piece of code I use in my project:

var advertisementWatcher = new BluetoothLEAdvertisementWatcher()
{
    SignalStrengthFilter.InRangeThresholdInDBm = -100,
    SignalStrengthFilter.OutOfRangeThresholdInDBm = -102,
    SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000)
};

advertisementWatcher.Received += AdvertisementWatcher_Received;
advertisementWatcher.Stopped += AdvertisementWatcher_Stopped;

advertisementWatcher.Start();

和后来

advertisementWatcher.Stop();

advertisementWatcher.Received -= AdvertisementWatcher_Received;
advertisementWatcher.Stopped -= AdvertisementWatcher_Stopped;

这篇关于在Windows10 UWP查找蓝牙的Mac地址,而配对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆