/// <summary> /// Gets number of steps for current day /// </summary> /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns> private async Task <bool> GetStepsAsync() { StepCounter stepCounter = null; try { stepCounter = await StepCounter.GetDefaultAsync(); _steps = await stepCounter.GetStepCountForRangeAsync( DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); } catch (Exception e) { _lastError = SenseHelper.GetSenseError(e.HResult); return(false); } finally { if (stepCounter != null) { stepCounter.Dispose(); } } return(true); }
/// <summary> /// Gets number of steps for current day /// </summary> /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns> private async Task <bool> GetStepsAsync() { // First try the pedometer try { var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromPedometerReadings(readings); return(true); } catch (Exception) { // Continue to the fallback } // Fall back to using Lumia Sensor Core. IStepCounter stepCounter = null; try { //var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues; if (DeviceTypeHelper.GetDeviceFormFactorType() == DeviceFormFactorType.Phone) { stepCounter = await StepCounter.GetDefaultAsync(); StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromLumiaStepCount(count); } else { var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt"); if (!await CallSensorCoreApiAsync(async() => { stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromLumiaStepCount(count); })) { return(false); } } } catch (Exception e) { _lastError = SenseHelper.GetSenseError(e.HResult); return(false); } finally { if (stepCounter != null && typeof(StepCounter) == stepCounter.GetType()) { ((StepCounter)stepCounter).Dispose(); } } return(true); }
/// <summary> /// Gets number of steps for current day /// </summary> /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns> private async Task <bool> GetStepsAsync() { // First try the pedometer try { var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromPedometerReadings(readings); return(true); } catch (Exception) { // Continue to the fallback } // Fall back to using Lumia Sensor Core. StepCounter stepCounter = null; try { stepCounter = await StepCounter.GetDefaultAsync(); StepCount count = await stepCounter.GetStepCountForRangeAsync( DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromLumiaStepCount(count); } catch (Exception e) { _lastError = SenseHelper.GetSenseError(e.HResult); return(false); } finally { if (stepCounter != null) { stepCounter.Dispose(); } } return(true); }
/// <summary> /// Gets the total steps till now. /// </summary> /// <returns></returns> private async Task<bool> GetStepsCounterAsync() { StepCounter stepCounter = null; try { _previousStepsReading = _stepsReading; stepCounter = await StepCounter.GetDefaultAsync(); _stepsReading = await stepCounter.GetStepCountAtAsync(DateTime.Now.Date); } catch (Exception e) { _lastError = SenseHelper.GetSenseError(e.HResult); return false; } finally { if (stepCounter != null) stepCounter.Dispose(); } return true; }
/// <summary> /// Gets number of steps for current day /// </summary> /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns> private async Task<bool> GetStepsAsync() { // First try the pedometer try { var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromPedometerReadings(readings); return true; } catch (Exception) { // Continue to the fallback } // Fall back to using Lumia Sensor Core. StepCounter stepCounter = null; try { stepCounter = await StepCounter.GetDefaultAsync(); StepCount count = await stepCounter.GetStepCountForRangeAsync( DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromLumiaStepCount(count); } catch (Exception e) { _lastError = SenseHelper.GetSenseError(e.HResult); return false; } finally { if (stepCounter != null) { stepCounter.Dispose(); } } return true; }
/// <summary> /// Gets number of steps for current day /// </summary> /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns> private async Task<bool> GetStepsAsync() { StepCounter stepCounter = null; try { stepCounter = await StepCounter.GetDefaultAsync(); _steps = await stepCounter.GetStepCountForRangeAsync( DateTime.Now.Date, DateTime.Now - DateTime.Now.Date ); } catch( Exception e ) { _lastError = SenseHelper.GetSenseError( e.HResult ); return false; } finally { if( stepCounter != null ) { stepCounter.Dispose(); } } return true; }