[英]How to detect BLE beacons on Unity3D HoloLens app?
I have built an app in Unity3D which should be able to detect Bluetooth Low-Energy beacons on the Microsoft HoloLens.我在 Unity3D 中构建了一个应用程序,它应该能够检测 Microsoft HoloLens 上的蓝牙低功耗信标。 Here is the Unity C# script code that I used to get this done.
这是我用来完成此任务的 Unity C# 脚本代码。
using UnityEngine;
using Windows.Devices.Bluetooth.Advertisement;
public class BeaconDetector : MonoBehaviour
{
private BluetoothLEAdvertisementWatcher _watcher;
void Start()
{
_watcher = new BluetoothLEAdvertisementWatcher();
_watcher.Received += WatcherOnReceived;
_watcher.Start();
}
//This method should be called when a beacon is detected
void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{
//Just a simple check if this method is even called
Debug.Log("Beacon detected!");
}
}
The app builds and runs on the HoloLens nicely, but (even after waiting a couple of minutes) I do not get the desired output line in my debug log.该应用程序可以很好地在 HoloLens 上构建和运行,但是(即使等待几分钟后)我的调试日志中也没有得到所需的输出行。 This means to me that the
WatcherOnReceived()
method is never called, which ultimately means that no beacon is detected .这对我来说意味着
WatcherOnReceived()
方法永远不会被调用,这最终意味着没有检测到信标。
I use some Sensoro SmartBeacon-4AA 's which can transmit both iBeacon and Eddystone signals.我使用了一些Sensoro SmartBeacon-4AA可以传输 iBeacon 和 Eddystone 信号。
I have been trying this for a couple of weeks right now, did several tutorials along the way but I still can not figure out why this is not working for me.我已经尝试了几个星期,一路上做了几个教程,但我仍然不明白为什么这对我不起作用。
It was a permission problem after all.毕竟是权限问题。 It is possible to solve this issue in both Unity (pre-build) and Visual Studio (post-build).
可以在 Unity(预构建)和 Visual Studio(构建后)中解决此问题。 Here are both solutions:
以下是两种解决方案:
Click on the .gif to expand
单击 .gif 以展开
Click on the .gif to expand
单击 .gif 以展开
This will give your app the right to use Bluetooth on the HoloLens.这将使你的应用有权在 HoloLens 上使用蓝牙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.