Accelerometer Shaken event in windows universal app doesn't work

痴心易碎 提交于 2019-12-23 23:56:28

问题


I try to detect a shake on my phone with the Shaken event from Accelerometer object. The accelerometer object is not null but when I shake the phone, it never go in the _accelerometer_Shaken event.

    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();
        });

    }

I don't understand why


回答1:


This feature is not supported yet.

This is an extract from the official sample code

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.

I made a test under Windows 10 10586 and it still does not work.



来源:https://stackoverflow.com/questions/34569608/accelerometer-shaken-event-in-windows-universal-app-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!