gpt4 book ai didi

c# - 无法通过蓝牙从 Windows 运行时组件连接到 Microsoft band

转载 作者:太空狗 更新时间:2023-10-29 17:59:09 26 4
gpt4 key购买 nike

我正在开发一个 Windows phone 8.1 应用程序,它与 Microsoft Band 连接以发送一些通知。我需要执行一些后台任务,因此我添加了一个Windows 运行时组件项目。

我正在从后台任务发送通知,即从运行时组件项目发送通知。但是我收到一个错误。错误如下:

Error: System.TypeInitializationException: The type initializer for 'Microsoft.Band.Store.StoreResources' threw an exception. ---> System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) at Windows.UI.Xaml.Application.get_Current() at Microsoft.Band.Store.StoreResources..cctor() --- End of inner exception stack trace --- at Microsoft.Band.Store.StoreResources.get_RfComm_FromId_ReturnedNull() at Microsoft.Band.Store.BluetoothTransport.GetTransport(RfcommDeviceService service, ILoggerProvider loggerProvider, UInt16 maxConnectAttempts) at Microsoft.Band.Store.BluetoothTransport.<>c__DisplayClass1.b__0() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()

如本 Question 中的回答所述在后台应用程序尝试连接时,前台应用程序不应尝试连接到手环。

  • 我的前台应用程序既没有尝试连接也没有任何与乐队的联系。

我认为错误是连接蓝牙的问题,因为我已经调试找到了错误的位置:

public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();

try
{
Debug.WriteLine("Task Triggered " + DateTime.Now);
taskInstance.Canceled += (s, e) => { };
taskInstance.Progress = 0;

// Get the list of Microsoft Bands paired to the phone.
var pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Length < 1)
{
Debug.WriteLine(
"This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.");
return;
}

// This is the line I am getting the error
using (var bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
Debug.WriteLine("Tile creation started");

我手环的蓝牙与 Microsoft Health 应用程序连接正常,所以我想我的手机和手环的蓝牙没有问题。

我的前台应用的 Package.appmanifest 如下:

Foreground app Package.appmanifest

Package.appmanifest 用于后台任务(Windows 运行时组件项目):

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Capabilities>
<DeviceCapability Name="bluetooth.rfcomm" xmlns="http://schemas.microsoft.com/appx/2013/manifest">
<Device Id="any">
<!-- Used by the Microsoft Band SDK -->
<Function Type="serviceId:A502CA9A-2BA5-413C-A4E0-13804E47B38F" />
<!-- Used by the Microsoft Band SDK -->
<Function Type="serviceId:C742E1A2-6320-5ABC-9643-D206C677E580" />
</Device>
</DeviceCapability>

那么可能的问题是什么?您能否提供此问题的解决方案或解决方法?

最佳答案

您是否在 Package.appxmanifest 文件中设置了正确的功能和声明?

您至少需要勾选功能(使用蓝牙)中的“Proximity”,并在声明中为后台任务指定类型和入口点。

关于c# - 无法通过蓝牙从 Windows 运行时组件连接到 Microsoft band,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31357343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com