I am developing application for windows phone 8.1 and need to detect phone movement.
For example, I need to detect one of two scenarios:
And here is the screenshot of application showing acelerometer readings when the phone is in position like on the second picture.
X-Axis, Y-Axis and Z-Axis are same (Same on my device). In the second picture when phone is facing up, X = -0.5317. Looks like that for some reason all axis take this value.
Here is the code.
public RoundPage()
{
this.InitializeComponent();
// ...
this._accelerometer = Accelerometer.GetDefault();
this._accelerometer.ReadingChanged += _accelerometer_ReadingChanged;
}
async void _accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
double xAxis = args.Reading.AccelerationX;
double yAxis = args.Reading.AccelerationY;
double zAxis = args.Reading.AccelerationZ;
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccTextBlock.Text = String.Format("X: {0:f2} Y: {0:f2} Z: {0:f2}",
xAxis,
yAxis,
zAxis);
});
}
What am I doing wrong? What is correct way do detect this readings.
我在String.Format方法中出错,我一直在打印xAxis({0})。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.