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