[HoloLens] Device permission dialog for RFCOMM Bluetooth serial port

Dear all,
I would like to use a Bluetooth serial device on the HoloLens. In theory, it should work like this:
Add this manually to you package.appxmanifest (because Unity does not offer a option to include it!)

<DeviceCapability Name="bluetooth.rfcomm">
  <Device Id="any">
    <Function Type="name:serialPort" />
  </Device>
</DeviceCapability>

Then, you find your Bluetooth device ID and try to open it with:

myRfcommDeviceService = await RFcommDeviceService.FromIdAsync(serial_Id);

At this point, Windows should display a device permission consent dialog (or permission request window) where the user can grant or deny the access to the device.

However, the pitfall is, that when FromIdAsync() is called from any background thread or task, it will silently fail, and you cannot access your device due to some error.

Well, after digging around some time, I found the solution: call FromIdAsync() from the UI-Thread ! But by default, your scripts don’t run on the UI-thread, so you have to use a trick:

UnityEngine.WSA.Application.InvokeOnUIThread(../*call FromIdAsync from here*/..)

Ok, now for the real problem: this freezes my app on the very first run. After I close the window (I need to sleep by using the power button), and try again, the permission dialog is shown.
The behaviour also depends on the my build settings: debug, release or master. master never seems to work.

I think the main problem is the context switch, because the Windows permission dialog is displayed in the “main” HoloLens area after your application is put in some sort of background mode.

So, does anyone also have this problem? Can Unity improve the experience?

Tested with Unity 2017.1.2

Hi ChrisSoy,

Can you possibly file a bug report on this using the Help menu? That would help us look into this a bit better.

Hey there!

Is there any progress concerning this problem? I’m trying the same thing (HoloLens should connect to a bluetooth device and receive data), and I’m stuck. I’ve been referencing these code samples:

I’m trying to call this code:

#region Client
        try
        {
            bluetoothDevice = await BluetoothDevice.FromIdAsync(deviceID);
        }
        catch (Exception e)
        {
            DebugText.text = "BluetoothDevice " + e.Message;
        }

Like this:

    public void ConnectToHumeds()
    {
#if UNITY_WSA_10_0 && NETFX_CORE
        DebugText.text = "Trying to connect...";
        //HumedsConnectAsync();
        UnityEngine.WSA.Application.InvokeOnUIThread(HumedsConnectAsync, true);
#endif
    }

Application just shuts down…

Thanks in advance!

P.S. If I solve it somehow, I’ll post the solution (if any).

Did you manage to communicate?