在Unity应用程序中为Hololens显示设备使用许可对话框

时间:2017-02-18 14:20:03

标签: c# unity3d uwp hololens

我正在开发基于Unity的Hololens应用程序。我的需求是使用Bluetooth Service Port Profile从手机(android或wp - 并不重要)获取一些信息。选择的方法是使Hololens充当蓝牙主机。所以我正在使用RfcommServiceProvider。简化样本:

_rfcommProvider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.SerialPort);
_socketListener = new StreamSocketListener();
_socketListener.ConnectionReceived += OnConnectionReceived;
await _socketListener.BindServiceNameAsync(_rfcommProvider.ServiceId.AsString(),
                                             SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
_rfcommProvider.StartAdvertising(_socketListener, true);

事件处理程序如:

private async void OnConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
    _socket = args.Socket;
    ...
}

接下来是问题:当客户端设备尝试连接时 - 用户需要为此应用/设备对授予权限。如果在hololens上的UWP应用程序中使用此代码,则会出现系统同意对话框。但是当它的Unity应用程序 - 它只是试图在事件处理程序中获取套接字。要修复此用户需要关闭应用,请转到设置>隐私>其他设备并打开设备/应用程序对的开关按钮(此按钮仅在首次尝试连接到Hololens应用程序后出现)。

所以问题是:在Unity应用程序中是否有一种明确的方式或一些解决方法要求用户提供此权限?

0 个答案:

没有答案