Here is a complete example that uses Android.Hardware.ISensorEventListener to detect a shake gesture. You should be able to opt out of this in your own projects without any problems.
[Activity (Label = "ShakeDetection", MainLauncher = true)] public class MainActivity : Activity, Android.Hardware.ISensorEventListener { bool hasUpdated = false; DateTime lastUpdate; float last_x = 0.0f; float last_y = 0.0f; float last_z = 0.0f; const int ShakeDetectionTimeLapse = 250; const double ShakeThreshold = 800; protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main);
The above activity implements the Android.Hardware.ISensorEventListener interface, and then registers it through the SensorManager . Actual sensor events (shaking, etc.) are passed to OnSensorChanged ; this is where we stick to the logic for our jitter detection code.
I based this answer on this , but made a few changes to it. First, this answer uses an ISensorEventListener , not an ISensorListener (which is deprecated at API level 3). And you will find that initial gesture detection is enabled (via hasUpdated ) and some variables to control the sensitivity of jitter. Playing with ShakeDetectionTimeLapse and ShakeDetectionThreshold , you can fine-tune it to your needs.
Cm:
source share