Example #1
0
        async Task GetOrRegisterProximityTaskAsync()
        {
            // This technique also valid for the Pedometer where you can specify
            // a particular step count.
            var deviceInfoList = await DeviceInformation.FindAllAsync(
                ProximitySensor.GetDeviceSelector());

            var deviceInfo = deviceInfoList.FirstOrDefault();

            if (deviceInfo != null)
            {
                var proximtySensor = ProximitySensor.FromId(deviceInfo.Id);
                var threshold      = new ProximitySensorDataThreshold(proximtySensor);
                var trigger        = new SensorDataThresholdTrigger(threshold);

                this.proximityTaskRegistration = FindOrRegisterBackgroundTaskFromLibrary(
                    "Proximity Trigger",
                    trigger);
            }
        }
Example #2
0
        /// <summary>
        /// Registers the background task.
        /// </summary>
        private void RegisterBackgroundTask()
        {
            var builder = new BackgroundTaskBuilder()
            {
                Name           = SampleBackgroundTaskName,
                TaskEntryPoint = SampleBackgroundTaskEntryPoint
            };

            // create a Proximity data threshold
            var threshold = new ProximitySensorDataThreshold(sensor);
            // create a trigger using the threshold
            var trigger = new SensorDataThresholdTrigger(threshold);

            builder.SetTrigger(trigger);

            BackgroundTaskRegistration task = builder.Register();

            task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

            registered = true;
            UpdateUIAsync("Registered");
        }
        /// <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");
        }
        /// <summary>
        /// Registers the background task.
        /// </summary>
        private void RegisterBackgroundTask()
        {
            var builder = new BackgroundTaskBuilder()
            {
                Name = SampleBackgroundTaskName,
                TaskEntryPoint = SampleBackgroundTaskEntryPoint
            };

            // create a Proximity data threshold
            var threshold = new ProximitySensorDataThreshold(sensor);
            // create a trigger using the threshold
            var trigger = new SensorDataThresholdTrigger(threshold);

            builder.SetTrigger(trigger);

            BackgroundTaskRegistration task = builder.Register();
            task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

            registered = true;
            UpdateUIAsync("Registered");
        }
        /// <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");
        }