private async void Button_Click(object sender, RoutedEventArgs e)
{
this.viewModel.StatusMessage = "Running ...";
try
{
// Get the list of Microsoft Bands paired to the phone.
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]))
{
int samplesReceived = 0; // the number of Accelerometer samples received
// Subscribe to Accelerometer data.
bandClient.SensorManager.Accelerometer.ReadingChanged += (s, args) => { samplesReceived++; };
await bandClient.SensorManager.Accelerometer.StartReadingsAsync();
// Receive Accelerometer data for a while, then stop the subscription.
await Task.Delay(TimeSpan.FromSeconds(5));
await bandClient.SensorManager.Accelerometer.StopReadingsAsync();
this.viewModel.StatusMessage = string.Format("Done. {0} Accelerometer samples were received.", samplesReceived);
}
}
catch (Exception ex)
{
this.viewModel.StatusMessage = ex.ToString();
}
}
}