Monday, 30 May 2016

Shake Detector in Android

maxresdefault.jpg

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.

No comments:

Post a Comment