【问题标题】:Microsoft Band 2 + UWP + Background Task => An error occurred while attempting to acquire the Bluetooth device serviceMicrosoft Band 2 + UWP + 后台任务 => 尝试获取蓝牙设备服务时出错
【发布时间】:2016-05-06 08:51:08
【问题描述】:

我正在我的 Surface Pro 3 上编写一个 Windows 10 UWP 应用程序,该应用程序连接到我的 Microsoft Band 2,当我在前台运行应用程序时,我可以很好地连接到它。

但现在我正在尝试使用 DeviceUseTrigger 并在后台任务中运行一些逻辑。当我调用连接乐队的方法时:

var bandInfo = (await BandClientManager.Instance.GetPairedBandsAsync()).FirstOrDefault();
var bandClient = await BandClientManager.Instance.ConnectAsync(bandInfo);

我收到以下错误:

尝试获取蓝牙设备时出错 服务。如果配对设备无法访问或 已与当前主机解除配对。

我在我的 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>

这是我对后台任务的声明:

<Extensions>
  <Extension Category="windows.backgroundTasks" EntryPoint="WindowsRuntimeComponent1.BandBackgroundTask">
     <BackgroundTasks>
        <Task Type="deviceUse" />
      </BackgroundTasks>
   </Extension>
</Extensions>

【问题讨论】:

    标签: bluetooth win-universal-app background-task microsoft-band


    【解决方案1】:

    只是猜测,但Band SDK documentation 中的这一段是否也有助于您拨打GetPairedBandsAsync

    如果您的应用想要从后台连接到 Band,那么 应用程序应调用 GetBandsAsync(isBackground: true) 以获取连接 不会干扰在前台运行的任何应用程序 并且当前使用的是 Band 连接。

    【讨论】:

    • 感谢您的回复,我确实错过了文档的那部分。我现在已经改变了这个,但不幸的是我仍然遇到同样的错误。不知道我做错了什么......:/
    猜你喜欢
    • 2014-10-11
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2015-01-26
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多