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

标签 c# windows-mobile win-universal-app shake

我尝试使用加速度计对象的 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/

相关文章:

c# - ASP.NET动态UserControl ID生成问题

c# - 由多个线程读取/写入的字段,Interlocked 与 volatile

c# - .NET Compact Framework - Windows Mobile 6.5 上的 CAB 自动更新

c++ - 是否有适用于 CE 和 Win32 的相机的通用 C++ API 或 SDKS

c# - 打开下拉列表时更改组合框中的项目索引

javascript - 如何在winjs上制作一个splitview菜单

vb.net - 从后端刷新时不要触发 ComboBox SelectionChanged

c# - 使用 Entity Framework 写入大量记录需要花费太多时间

c# - 大名单语音识别

.net - "Release"中的构建过程卡在 UWP 应用程序中