/// <summary>
        /// Registers the pedometer background task with a step goal of 50 steps.
        /// </summary>
        private void RegisterBackgroundTask()
        {
            // build the background task with the known entry points for Pedometer background task
            var builder = new BackgroundTaskBuilder()
            {
                Name           = SampleBackgroundTaskName,
                TaskEntryPoint = SampleBackgroundTaskEntryPoint
            };

            // Get the current readings to find the current step counters
            var currentReadings = sensor.GetCurrentReadings();

            stepCount = 0;
            foreach (PedometerStepKind kind in Enum.GetValues(typeof(PedometerStepKind)))
            {
                PedometerReading reading;
                if (currentReadings.TryGetValue(kind, out reading))
                {
                    stepCount += reading.CumulativeSteps;
                }
            }

            // set a new step goal
            stepGoal = stepCount + Scenario4_BackgroundPedometer.stepGoalOffset;
            // create a Pedometer data threshold for that step goal
            var threshold = new PedometerDataThreshold(sensor, stepGoal);
            // create a sensor trigger using the above threshold
            var trigger = new SensorDataThresholdTrigger(threshold);

            builder.SetTrigger(trigger);

            BackgroundTaskRegistration task = builder.Register();

            task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

            backgroundTaskRegistered = true;
            UpdateUIAsync("Registered");
        }
コード例 #2
0
        private async void start()
        {
            var aa = pedometer.GetCurrentReadings();

            rs = aa[PedometerStepKind.Running].CumulativeSteps;
            ws = aa[PedometerStepKind.Walking].CumulativeSteps;
            double p  = pressure.GetCurrentReading().StationPressureInHectopascals;
            double h  = Math.Round(nowH, 1);
            double la = 200;
            double lo = 200;

            try
            {
                Geolocator geolocator = new Geolocator();
                // 获取当前的位置
                Geoposition pos = await geolocator.GetGeopositionAsync();

                //纬度
                la = pos.Coordinate.Point.Position.Latitude;
                //经度
                lo = pos.Coordinate.Point.Position.Longitude;
            }
            catch (UnauthorizedAccessException)
            {
                //未授权的访问异常
            }
            catch (Exception ex)
            {
                //超时 time out
            }
            dm.start(h, p, ws, rs, la, lo);
            var settings = ApplicationData.Current.LocalSettings;

            settings.Values["startRS"] = rs;
            settings.Values["startWS"] = ws;
        }