Shake Detector in Android


In Android, the most commonly used sensors are the accelerometer, it is used to measure acceleration. Here it is explained how to detect a shake motion.

Step 1. Create Class ShakeDetector that will extend SensorEventListener:-

Step 1(a) :-  Declare the required variable :-

  1. /*gForce Must be greater than 1G (one earth gravity unit).*/
  2. private static final float THRESHOLD_GRAVITY = 3.2F;
  3. private static final int SLOP_TIME_MS = 1000; /*This decide after how much interval shake will detect */
  4. private static final int COUNT_RESET_TIME_MS = 3000;
  5. private Double mAccelCurrent, gForce = 0.00, mAccelLast = 0.00, mAccel = 0.00;
  6. private OnShakeListener mListener;
  7. private long mShakeTimestamp;
  8. private int mShakeCount;

Read more about the Shake Detector in Android visit Findnerd.

Shake Detector in Android

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s