The background task registration code looks like this:
var builder = new BackgroundTaskBuilder();
builder.Name = name;
builder.TaskEntryPoint = typeof(BackgroundTaskClass).FullName;
var trigger = new GattCharacteristicNotificationTrigger(characteristic);
builder.SetTrigger(trigger);
btr = builder.Register();
The entry in the manifest is:
<Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTaskNS.BackgroundTaskClass">
<BackgroundTasks>
<Task Type="deviceConnectionChange" />
<Task Type="bluetooth" />
</BackgroundTasks>
</Extension>
The Register() method triggers this error:
Access is denied.
Your App does not have permission to use the Gatt Service in the background. Make sure you have declared the DeviceCapability and Task Type 'bluetooth' in your manifest and that the application has been granted access to this device.
This only happens on Creators Update installed on the build machine and also targeting the Creators Update SDK. This worked well before we updated the SDK and the build machine.
We've had the same issue with UWP app on windows 10 mobile.
We updated windows 10 mobile to build 10.0.15230.0, then deleted the app (manually on a phone) and installed it again. Now it works fine. Also we installed last version of SDK, but I think this step can be skipped.
In the compatibility section of your manifest, add this:
<Capabilities>
<DeviceCapability Name="bluetooth" />
</Capabilities>
Didn't see it in your code sample. Could be that you need to call RequestAccessAsync
from a UX thread on the GattDeviceService which contains the characteristic before registering your trigger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With