Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to Microsoft band from Windows Runtime Component through Bluetooth

I am developing a Windows phone 8.1 app which connects with a Microsoft Band to send some notification. I need to perform some background tasks, so I have added a Windows Runtime Component project.

I am sending the notification from the background task i.e. from the Runtime component project. But I am getting an error. The error is as follows:

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()

As said in an answer in this Question that the foreground app should not try to connect to the band while the background app is trying to connect.

  • My foreground app is not trying to connect nor does have any connection with the band.

I think the error is for problems in connecting to Bluetooth, because I have debugged and found out the location of the error:

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");

My band's Bluetooth is connecting fine with Microsoft Health app, so I suppose there is nothing wrong with Bluetooth of my phone and band.

My Package.appmanifest for Foreground app is as follows:

Foreground app Package.appmanifest

Package.appmanifest for Background Task ( Windows Runtime Component project):

<?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>

So what can be the possible issue? Can you provide a solution or a work-around to this problem?

like image 921
Utsav Dawn Avatar asked Jul 11 '15 12:07

Utsav Dawn


People also ask

How to identify the target Bluetooth device in the connect function?

The name parameter of the connect function, which is a SOCKADDR_BTH structure, must specify a target Bluetooth device. Two mechanisms are used to identify the target device: The SOCKADDR_BTH structure can directly specify the port number to which a connect is requested.

What is the use of Bluetooth connect function?

Bluetooth uses the connect function to connect to a target Bluetooth device, using a previously created Bluetooth socket. The name parameter of the connect function, which is a SOCKADDR_BTH structure, must specify a target Bluetooth device. Two mechanisms are used to identify the target device:

What is the Bluetooth service class and Port?

The service class is a normalized 128-bit GUID, defined by the Bluetooth specification. Common GUIDs are defined by the Bluetooth Assigned Numbers document. Alternatively, a unique GUID may be used for a domain-specific application. The port member must be a valid remote port, or zero if the serviceClassId member is specified.


1 Answers

Have you set the right capabilities and declarations in the Package.appxmanifest file?

As a minimum you need to check off "Proximity" in capabilities (to use Bluetooth) and specify a type and entry point for the background task in declarations.

like image 102
Jens Avatar answered Oct 04 '22 16:10

Jens