windows 通用应用程序中的加速度计震动事件不起作用

Accelerometer Shaken event in windows universal app doesn't work

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

我在Windows10 10586下测试了,还是不行