public void RemoveStepCountEntry(StepCountEntry entry) { //Cast the entry as a HealthKitBloodGlucoseEntry... HealthKitStepCountEntry hkStepCountEntry = entry as HealthKitStepCountEntry; HealthStore.DeleteObject(hkStepCountEntry.StepCountSample, new Action <bool, NSError> ((success, error) => { if (!success || error != null) { //NOTE: If this app didn't put the entry into the blood glucose list, then there will be an error on delete. AlertManager.ShowError("Health Kit", "Unable to delete step count sample: " + error); } else { //Woo! We properly removed the last entry, make sure that any listeners to the glucose states are properly updated. RefreshQuantityValue(HKQuantityTypeIdentifierKey.StepCount, HKObjectType.GetQuantityType(HKQuantityTypeIdentifierKey.StepCount)); } })); }
public void AddStepCountEntry(StepCountEntry entry) { var date = new NSDate(); var quantityType = HKObjectType.GetQuantityType(HKQuantityTypeIdentifierKey.StepCount); var countUnit = HKUnit.Count; var quantity = HKQuantity.FromQuantity(countUnit, entry.Count); var sample = HKQuantitySample.FromType(quantityType, quantity, date, date); HealthStore.SaveObject(sample, new Action <bool, NSError>((success, error) => { if (!success || error != null) { //There may have been an add error for some reason. AlertManager.ShowError("Health Kit", "Unable to add step count sample: " + error); } else { //Refresh all app wide blood glucose UI fields. RefreshQuantityValue(HKQuantityTypeIdentifierKey.StepCount, quantityType); } })); }
public async void AddStepCountEntry(StepCountEntry entry) { Log.Info(TAG, "Creating a new data insert request"); // Set a start and end time for our data, using a start time of 1 hour before this moment. DateTime endTime = DateTime.Now; DateTime startTime = endTime.Subtract(TimeSpan.FromHours(1)); long endTimeElapsed = GetMsSinceEpochAsLong(endTime); long startTimeElapsed = GetMsSinceEpochAsLong(startTime); // Create a data source var dataSource = new DataSource.Builder() .SetAppPackageName(this._activity) .SetDataType(Android.Gms.Fitness.Data.DataType.TypeStepCountDelta) .SetName(TAG + " - step count") .SetType(DataSource.TypeRaw) .Build(); // Create a data set //const int stepCountDelta = 1000; var dataSet = DataSet.Create(dataSource); DataPoint dataPoint = dataSet.CreateDataPoint() .SetTimeInterval(startTimeElapsed, endTimeElapsed, TimeUnit.Milliseconds); dataPoint.GetValue(Field.FieldSteps).SetInt(Convert.ToInt32(entry.Count)); dataSet.Add(dataPoint); Log.Info(TAG, "Inserting the dataset in the History API"); var insertStatus = await FitnessClass.HistoryApi.InsertDataAsync(mClient, dataSet); if (!insertStatus.IsSuccess) { Log.Info(TAG, "There was a problem inserting the dataset."); return; } Log.Info(TAG, "Data insert was successful!"); RefreshHealthStateData(); }
public void RemoveStepCountEntry(StepCountEntry entry) { //Google Fit doesn't support Blood Glucose, but we could add it as a custom type. throw new NotImplementedException(); }