Using the Motion Sensor
The sample code for this section follows the same pattern as the code for the gyroscope. The viewmodel’s Start
method first tests whether the motion sensor is supported, and then creates a new Motion
instance, subscribes to its CurrentValueChangedEvent
, and calls its Start
method. See the following excerpt:
public void Start(){ if (!Motion.IsSupported) { MessageService.ShowMessage( "Motion is not supported on this device."); return; } motion = new Motion(); double interval = motion.TimeBetweenUpdates.TotalMilliseconds; motion.CurrentValueChanged += HandleMotionCurrentValueChanged; motion.Start();}
The Motion
sensor’s TimeBetweenUpdates
property ...
Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.