I'm working on application for Hololens built on Unity. My need is to get some information from phone(android or wp - doesn't really matter) using Bluetooth Service Port Profile
. The chosen approach is to make a Hololens act as Bluetooth Host. So I'm using RfcommServiceProvider
for this. The simplified sample:
_rfcommProvider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.SerialPort);
_socketListener = new StreamSocketListener();
_socketListener.ConnectionReceived += OnConnectionReceived;
await _socketListener.BindServiceNameAsync(_rfcommProvider.ServiceId.AsString(),
SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
_rfcommProvider.StartAdvertising(_socketListener, true);
And event handler like:
private async void OnConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
_socket = args.Socket;
...
}
The issue is next: when client device tries to connect - user need to grant permission for this app/device pair. If use this code in UWP app on hololens - system consent dialog appears. But when it's Unity app - it just failes on attempt to get socket in event handler. To fix this user need to close app, go to Settings > Privacy > Other devices and turn on switch button for device/app pair(this button appears there only after first attempt to connect to Hololens app).
So the question: is there a distinct way or some workaround to ask user for this permission inside Unity app?