Search code examples
c#microsoft-band

MS Band continue reading values on lockscreen


I try to read accelerometer values from the band even if

  • The phone is locked
  • The app hasn't the focus

Reading values while the app has the focus works quite well. But if I press the "Windows" button and working on other apps, no ChangedEventArgs will be fired anymore.

I would like to collect accelerometer and gyro data over the whole day to determin what the user who is wearing the band is doing. (Pattern recognition for eating, drinking etc.)

Is this possible with the default Microsoft.Band SDK?

My code

            IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
            IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]);
            if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() != UserConsent.Granted)
            {
                await bandClient.SensorManager.Gyroscope.RequestUserConsentAsync();
            }

            bandClient.SensorManager.Gyroscope.ReadingChanged += Gyroscope_ReadingChanged;
            await bandClient.SensorManager.Gyroscope.StartReadingsAsync();

Solution

  • Instead of using a TimeTrigger background task, you could explore the DeviceUseTrigger to get a "near-permanent" connection to the band. While I haven't tried it myself, below article details the necessary steps. I think it is a feasible approach considering your requirements?

    http://www.codeproject.com/Tips/1036512/Achieveing-Indefinite-Background-Execution-with-th