是否可以在 Windows 运行时组件中使用 Microsoft Band SDK?GetBandsAsync
有效,但在使用以下连接时失败:
IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])
我正在使用 Microsoft Band SDK 1.3.10518。我已将 rfcomm 功能添加到应用程序包清单中,但出现以下异常:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.Band.MarshalUtils.GetBytes[T](T& structure, Byte[] resultArray, Int32 offset)
at Microsoft.Band.BandClient.CheckFirmwareSdkBit(FirmwareSdkCheckPlatform platform, Byte reserved)
at Microsoft.Band.BandClientManager.<ConnectAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BandController.Band.<StartRemoteControlAsync>d__5.MoveNext()} System.Exception {System.IO.FileNotFoundException}
为了重现错误,这就是我所做的:
- 在 Visual Studio 中创建一个新的空白应用程序 (Windows Phone Silverlight)
- 向应用程序添加一个按钮(比如说“测试带”)并为 Tap 事件添加一个处理程序
- 将 Windows 运行时组件 (Windows Phone) 添加到解决方案中,将其命名为 BandTest,命名空间 BandWrapper
- 将 Microsoft Band SDK 添加到 BandWrapper 项目
- 在 Silverlight 项目的 Package.appxmanifext 中添加 rfcomm 和邻近功能(对于 BandWrapper rfcomm 由 Microsoft Band SDK 安装程序添加)
实现测试按钮处理程序如下:
private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e) { BandWrapper.BandTest wrapper = new BandWrapper.BandTest(); 包装器.TestBand(); }
并在从 SDK 示例中复制以下运行时组件的
public async void TestBand()
方法中:try { // Get the list of Microsoft Bands paired to the phone/tablet/PC. IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync(); if (pairedBands.Length < 1) { //this.viewModel.StatusMessage = "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; } // Connect to Microsoft Band. using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])) { // We'll create a Tile that looks like this: // +--------------------+ // | MY CARD | // | ||||||||||||||||| | // | 123456789 | // +--------------------+ // First, we'll prepare the layout for the Tile page described above. TextBlock myCardTextBlock = new TextBlock() { Color = Colors.Blue.ToBandColor(), ElementId = 1, // the Id of the TextBlock element; we'll use it later to set its text to "MY CARD" Rect = new PageRect(0, 0, 200, 25) };
...
如果在上面的步骤 1. 中,我创建了一个 Windows Phone 应用程序(不是 Silverlight),那么测试方法的执行将上升到
await bandClient.TileManager.AddTileAsync(myTile);
它失败了:
System.TypeLoadException: Could not find Windows Runtime type 'Windows.Foundation'.
at System.StubHelpers.WinRTTypeNameConverter.GetTypeFromWinRTTypeName(String typeName, Boolean& isPrimitive)
at System.StubHelpers.SystemTypeMarshaler.ConvertToManaged(TypeNameNative* pNativeType, Type& managedType)
at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
at Microsoft.Band.StoreApplicationPlatformProvider`2.<>c__DisplayClassd`1.<GetConsentAsync>b__a()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Band.StoreApplicationPlatformProvider`2.<GetConsentAsync>d__f`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Band.BandClient.<>c__DisplayClass6f.<<AddTileAsync>b__6c>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BandWrapper.BandTest.<TestBand>d__5.MoveNext()} System.Exception {System.TypeLoadException}