[UWP] Windows.Devices.Sensors.Accelerometer.Shaken无效 [英] [UWP]Windows.Devices.Sensors.Accelerometer.Shaken is not working
问题描述
我正在开发Windows 10中的Accelerometer内容。请查看以下观察结果。
I am working on Accelerometer stuff in windows 10. Please find the below observations.
1。我有Windows 8应用程序,它使用Accelerometer API,并注册到Shaken事件
1. I have windows 8 app, which uses Accelerometer API, and registered to Shaken event
案例1:Windows 8.1操作系统设备收到"动摇"事件
case 1: Windows 8.1 OS device received "Shaken" event
案例2:未收到Widows 10(Build no 10240)"Shaken"事件
case 2: Widows 10 (Build no 10240) is not received "Shaken" event
2。我创建了示例windows 10 app,它使用了Accelerometer API,并注册了Shaken事件
2. I have created sample windows 10 app, which uses Accelerometer API, and registered to Shaken event
行为: ;未收到寡妇10(建筑编号10240)"摇动"事件
behavior: Widows 10 (Build no 10240) is not received "Shaken" event
我不明白这个问题。我们是否有其他API来检测"Shake"。或者它是Windows 10 OS内部问题。
I don't understood the problem. Do we have other API to detect "Shake". OR It is windows 10 OS internal Issue.
注意:我使用的是DELL Latitude 10 - ST2e
Note: I am using DELL Latitude 10 - ST2e
谢谢,
Pallam Madhukar Windows Phone开发人员
Pallam Madhukar Windows Phone Developer
推荐答案
嗨帕拉姆,
>>行为: 未收到寡妇10(建造号10240)"摇动"。事件
>>behavior: Widows 10 (Build no 10240) is not received "Shaken" event
实际上,Windows 10 Mobile还没有发布,所以我不知道这是否适用于RTM windows10 SDK。无论如何,这在Windows Mobile 10149上不起作用。
Actually, the Windows 10 Mobile has not been released, so I don't know if this should work for the RTM windows10 SDK. Anyway, this don't work on Windows Mobile 10149.
作为一种解决方法,您可以处理
Accelerometer.ReadingChanged 事件并分析数据更改频率以确定设备是否在抖动:
As a workaround, you can handle Accelerometer.ReadingChanged event and analysis the data change frequency to determine if the device is shaking:
Accelerometer _accelerometer = Accelerometer.GetDefault();
private async void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading != null)
{
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
}
});
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (_accelerometer != null)
{
// Establish the report interval
uint minReportInterval = _accelerometer.MinimumReportInterval;
uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
_accelerometer.ReportInterval = reportInterval;
// Assign an event handler for the reading-changed event
_accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
}
else
{
Debug.WriteLine("No accelerometer found");
}
}
这篇关于[UWP] Windows.Devices.Sensors.Accelerometer.Shaken无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!