I'm writing a Windows 10 UWP app on my Surface Pro 3 which is connected to my Microsoft Band 2 and I can connect to it just fine when I'm running the app in the foreground.
But now I'm trying to use the DeviceUseTrigger and run some logic in a background task. When I call the method to connect to the band:
var bandInfo = (await BandClientManager.Instance.GetPairedBandsAsync()).FirstOrDefault();
var bandClient = await BandClientManager.Instance.ConnectAsync(bandInfo);
I get the following error:
An error occurred while attempting to acquire the Bluetooth device service. This error can occur if the paired device is unreachable or has become unpaired from the current host.
I added the following capabilities to my UWP appxmanifest:
<DeviceCapability Name="bluetooth" />
<DeviceCapability Name="location" />
<DeviceCapability Name="proximity" />
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type="serviceId:A502CA9A-2BA5-413C-A4E0-13804E47B38F" />
<Function Type="serviceId:C742E1A2-6320-5ABC-9643-D206C677E580" />
</Device>
</DeviceCapability>
And this is my declaration of the background task:
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="WindowsRuntimeComponent1.BandBackgroundTask">
<BackgroundTasks>
<Task Type="deviceUse" />
</BackgroundTasks>
</Extension>
</Extensions>