我尝试使用加速度计对象的 Shaken 事件检测手机上的震动。加速度计对象不为 null,但当我摇动手机时,它永远不会进入 _accelerometer_Shaken
事件。
public int shakeCount = 0;
Accelerometer _accelerometer = Accelerometer.GetDefault();
public MainPage()
{
this.InitializeComponent();
if (_accelerometer != null)
{
_accelerometer.Shaken += _accelerometer_Shaken;
}
}
async private void _accelerometer_Shaken(Accelerometer sender, AccelerometerShakenEventArgs args)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
shakeCount++;
tbInfo.Text = shakeCount.ToString();
});
}
不明白为什么
最佳答案
尚不支持此功能。
这是官方示例代码的摘录
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Accelerometer
Accelerometer Shake Events
When you choose the Enable button for the Shake Events option, the app displays the cumulative number of shake events each time an event occurs. (The app first increments the event count and then renders the most recent value.)
Note that shake events are not supported in Windows 10 build 10240, so the Shaken event will never be raised, but the sample demonstrates how to handle the event when support for shake is added.
我在Windows 10 10586下进行了测试,仍然无法运行。
关于c# - Windows 通用应用程序中的加速度计摇动事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34569608/