gpt4 book ai didi

c# - Windows 通用应用程序中的加速度计摇动事件不起作用

转载 作者:行者123 更新时间:2023-11-30 23:31:28 25 4
gpt4 key购买 nike

我尝试使用来自 Accelerometer 对象的 Shaken 事件检测我手机上的震动。加速度计对象不为空,但当我摇动手机时,它永远不会进入 _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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com