我从后台任务即Runtime组件项目中发送通知。但是出现了错误。错误如下:
正如在这个问题的答案中所说,前台应用程序不应在后台应用程序尝试连接时尝试连接到手环。Error: System.TypeInitializationException: 'Microsoft.Band.Store.StoreResources'的类型初始化程序引发了异常。---> System.Exception: 灾难性故障 (HRESULT 的异常:0x8000FFFF (E_UNEXPECTED)) at Windows.UI.Xaml.Application.get_Current() at Microsoft.Band.Store.StoreResources..cctor() --- 内部异常堆栈跟踪的结尾 --- 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()
- 我的前台应用程序既没有尝试连接也没有与手环建立任何连接。
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");
我的手环与微软健康应用程序的蓝牙连接良好,因此我认为我的手机和手环的蓝牙没有问题。
我前台应用程序的快照中的Package.appmanifest如下所示: Windows Runtime组件项目的后台任务的Package.appmanifest如下所示:
<?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>
那么可能出现的问题是什么?你能提供一个解决方案或解决这个问题的方法吗?