none
[UWP]Windows.Devices.Sensors.Accelerometer.Shaken is not working RRS feed

  • Question

  • Hi,

    I am working on Accelerometer stuff in windows 10. Please find the below observations.

    1. I have windows 8 app, which uses Accelerometer API, and registered to Shaken event

    case 1: Windows 8.1 OS device received "Shaken" event  

    case 2: Widows 10 (Build no 10240) is not received "Shaken" event

    2. I have created sample windows 10 app, which uses Accelerometer API, and registered to Shaken event

    behavior:  Widows 10 (Build no 10240) is not received "Shaken" event

    I don't understood the problem. Do we have other API to detect "Shake". OR It is windows 10 OS internal Issue.

    Note: I am using DELL Latitude 10 - ST2e

    Thanks,


    Pallam Madhukar Windows Phone Developer

    Thursday, July 30, 2015 5:48 AM

All replies

  • Hi Pallam,

    >>behavior:  Widows 10 (Build no 10240) is not received "Shaken" event

    Actually, the Windows 10 Mobile has not been released, so I don't know if this should work for the RTM windows10 SDK. Anyway, this don't work on Windows Mobile 10149.

    As a workaround, you can handle Accelerometer.ReadingChanged event and analysis the data change frequency to determine if the device is shaking:

    Accelerometer _accelerometer = Accelerometer.GetDefault();
    
    private async void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
    {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    AccelerometerReading reading = _accelerometer.GetCurrentReading();
                    if (reading != null)
                    {
                        ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
                        ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
                        ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
                    }
    
                });
    }
    
    private void Button_Click(object sender, RoutedEventArgs e)
    {
                if (_accelerometer != null)
                {
                    // Establish the report interval
                    uint minReportInterval = _accelerometer.MinimumReportInterval;
                    uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
                    _accelerometer.ReportInterval = reportInterval;
    
                    // Assign an event handler for the reading-changed event
                    _accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
    
                }
                else
                {
                    Debug.WriteLine("No accelerometer found");
                }
    }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 31, 2015 6:09 AM
    Moderator
  • I am using Windows 10 10586, the Windows.Devices.Sensors.Accelerometer Shaken event still not working,

    public event TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs> Shaken;

    This also happens to the official sample code: https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/Accelerometer/cs/Scenario2_ShakeEvents.xaml.cs

    I tried on my Surface Pro 3 and Lumia 950XL, no matter how I try to shake the device, the count is still 0.

    Monday, January 11, 2016 5:52 AM
  • Hi Franklin Chen,

    Still we are not able to get "public event TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs> Shaken" event with latest Windows 10 update 10586. Currently we are using your suggestion for windows 10. But existing windows 8 code also is not working in windows 10.

    Please provide more information regarding "When we will get this feature in Windows 10/Windows 10 mobile".

    Thanks 


    Pallam Madhukar Windows Phone Developer

    Thursday, January 28, 2016 5:35 AM