BluetoothLEAdvertisementWatcher。 Hololens 上没有活动
BluetoothLEAdvertisementWatcher. No events on Hololens
我正在尝试通过 BLE 广告将 GPS 坐标从 Android 设备发送到 Hololens。
据我所知,来自 BluetoothLEAdvertisementWatcher 的事件不会在 Hololens 上触发。
我试过复制粘贴这两个 implementation
在接收端,没有接收到事件。
这是Unity中的当前实现,我在一个空白的UWP-C#项目中实现了相同的功能,并直接部署在Hololens上,结果相同。
private void StartWatcher()
{
void OnAdvertisementReceived(object sender, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
void OnAdvertisementStop(object sender, BluetoothLEAdvertisementWatcherStoppedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
try {
BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher();
watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(GetManufacturerData());
watcher.Received += OnAdvertisementReceived;
watcher.Stopped += OnAdvertisementStop;
watcher.Start();
Debeug.Log("Started"); // switched to Write-line on the C#->UWP implementation
} catch (Exception e){
}
}
private BluetoothLEManufacturerData GetManufacturerData()
{
var manufacturerData = new BluetoothLEManufacturerData();
manufacturerData.CompanyId = 0X06EF;
return manufacturerData;
我知道广告已发送,因为如果我直接在 PC 上 Visual Studio 中调试本机 UWP 应用程序(即使是 ARM64),一切正常。事件被触发。
watcher.Status
报告在 Hololens 上“开始”
即使我在应用程序处于 运行 时禁用 HoloLens 上的蓝牙,也不会触发停止事件。
如果我在禁用蓝牙后检查 watcher.Status
,状态报告中止但未收到停止事件。
能力在这之后被激活article
现在到了奇怪的地方。
在我的第一次尝试中,我在 Hololens 上安装了我的应用程序 运行,因为我试图删除 Android 设备和 HoloLens 之间的配对。
android 设备在 Hololens 上显示为两个设备,设备名称为一个,“LE”+MAC 为另一个。
在我进入蓝牙设置并从手机上取下两个适配器的某个时候,HoloLens 收到了三个独立的广告。广告中的数据也已从我的 Android 设备得到确认,因为在我最初的尝试中我解析了数据。
但就是这样,我今天尝试复制了 10 个小时,在不同阶段配对和取消配对不同的适配器,同时收听接收事件但没有运气。
在我的电脑上,适配器是否配对并不重要。
我已经尝试将 .NET Standard 2.0 和 .Net 4.x 作为 API 兼容级别。
我在接收和停止事件处理程序中都设置了断点,因为我担心来自事件函数的调用是问题所在。据我所知,我们从未达到实施的事件。
如有任何关于下一步检查的建议,我们将不胜感激。
Hololens Build 是 19041.1144。
好的,所以我现在可以通过运行微软证明的例子在HoloLens上接收广告。
我根本无法收到任何事件,设置中也没有可用的更新,所以我重新安装了 Microsoft Store 中的所有应用程序,这似乎是我的解决方案。之后,重新启动 HoloLens,我能够从我的 PC 接收广告。
关于尝试在 HoloLens 2 上接收广告的人们的其他提示的另一个提示。
当我能够从我的电脑接收广告时,我发现来自我的 Android 设备的广告没有在 HoloLens 上收到,但在 PC 上收到。
我 PC 上的广告类型为 NonConnectableUndirected,来自我的 Android 设备 ScannableUndirected。
我需要更改为“AdvertisingSet”,并在 AdvertisingSetParameters 中将 isConnectable 和 isScannable 都设置为 false,以便能够发送 NonConnectableUndirected。
现在 HoloLens 从我的 Android 设备接收广告。
我正在尝试通过 BLE 广告将 GPS 坐标从 Android 设备发送到 Hololens。 据我所知,来自 BluetoothLEAdvertisementWatcher 的事件不会在 Hololens 上触发。
我试过复制粘贴这两个 implementation
这是Unity中的当前实现,我在一个空白的UWP-C#项目中实现了相同的功能,并直接部署在Hololens上,结果相同。
private void StartWatcher()
{
void OnAdvertisementReceived(object sender, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
void OnAdvertisementStop(object sender, BluetoothLEAdvertisementWatcherStoppedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
try {
BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher();
watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(GetManufacturerData());
watcher.Received += OnAdvertisementReceived;
watcher.Stopped += OnAdvertisementStop;
watcher.Start();
Debeug.Log("Started"); // switched to Write-line on the C#->UWP implementation
} catch (Exception e){
}
}
private BluetoothLEManufacturerData GetManufacturerData()
{
var manufacturerData = new BluetoothLEManufacturerData();
manufacturerData.CompanyId = 0X06EF;
return manufacturerData;
我知道广告已发送,因为如果我直接在 PC 上 Visual Studio 中调试本机 UWP 应用程序(即使是 ARM64),一切正常。事件被触发。
watcher.Status
报告在 Hololens 上“开始”
即使我在应用程序处于 运行 时禁用 HoloLens 上的蓝牙,也不会触发停止事件。
如果我在禁用蓝牙后检查 watcher.Status
,状态报告中止但未收到停止事件。
能力在这之后被激活article
现在到了奇怪的地方。 在我的第一次尝试中,我在 Hololens 上安装了我的应用程序 运行,因为我试图删除 Android 设备和 HoloLens 之间的配对。 android 设备在 Hololens 上显示为两个设备,设备名称为一个,“LE”+MAC 为另一个。 在我进入蓝牙设置并从手机上取下两个适配器的某个时候,HoloLens 收到了三个独立的广告。广告中的数据也已从我的 Android 设备得到确认,因为在我最初的尝试中我解析了数据。
但就是这样,我今天尝试复制了 10 个小时,在不同阶段配对和取消配对不同的适配器,同时收听接收事件但没有运气。 在我的电脑上,适配器是否配对并不重要。
我已经尝试将 .NET Standard 2.0 和 .Net 4.x 作为 API 兼容级别。 我在接收和停止事件处理程序中都设置了断点,因为我担心来自事件函数的调用是问题所在。据我所知,我们从未达到实施的事件。
如有任何关于下一步检查的建议,我们将不胜感激。
Hololens Build 是 19041.1144。
好的,所以我现在可以通过运行微软证明的例子在HoloLens上接收广告。 我根本无法收到任何事件,设置中也没有可用的更新,所以我重新安装了 Microsoft Store 中的所有应用程序,这似乎是我的解决方案。之后,重新启动 HoloLens,我能够从我的 PC 接收广告。
关于尝试在 HoloLens 2 上接收广告的人们的其他提示的另一个提示。 当我能够从我的电脑接收广告时,我发现来自我的 Android 设备的广告没有在 HoloLens 上收到,但在 PC 上收到。 我 PC 上的广告类型为 NonConnectableUndirected,来自我的 Android 设备 ScannableUndirected。 我需要更改为“AdvertisingSet”,并在 AdvertisingSetParameters 中将 isConnectable 和 isScannable 都设置为 false,以便能够发送 NonConnectableUndirected。 现在 HoloLens 从我的 Android 设备接收广告。