如何在Unity3D HoloLens应用程序中检测BLE信标?

问题描述 投票:1回答:1

我在Unity3D中构建了一个应用程序,它应该能够在Microsoft HoloLens上检测蓝牙低能量信标。这是我用来完成这项工作的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!");
    }

}

该应用程序很好地构建并运行在HoloLens上,但是(即使等待几分钟后)我的调试日志中也没有得到所需的输出行。这对我来说意味着永远不会调用WatcherOnReceived()方法,这最终意味着没有检测到信标。

我使用一些可以传输iBeacon和Eddystone信号的Sensoro SmartBeacon-4AA。

我现在已经尝试了几个星期,沿途做了几个教程,但我仍然无法弄清楚为什么这对我不起作用。

为了您的信息,我做了这个tutorial(以及其他),并且还遇到了Andreas Jakl的Universal Beacon Library。

c# unity3d bluetooth-lowenergy beacon hololens
1个回答
3
投票

毕竟这是一个许可问题。可以在Unity(预构建)和Visual Studio(构建后)中解决此问题。以下是两种解决方案:

Solution A: in Unity

  1. 前往编辑>项目设置>播放器。
  2. 在“检查器”中,打开“发布设置”选项卡。
  3. 在“功能”部分下,确保已启用蓝牙。

enter image description here点击.gif文件进行展开

Solution B: in Visual Studio (2017)

  1. 在解决方案资源管理器(Ctrl + Alt + L)中,展开项目。
  2. 双击Package.appxmanifest。
  3. 转到功能选项卡。
  4. 再次确保启用蓝牙。

enter image description here点击.gif文件进行展开

这将使您的应用程序有权在HoloLens上使用蓝牙。

© www.soinside.com 2019 - 2024. All rights reserved.