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 :-
- /*gForce Must be greater than 1G (one earth gravity unit).*/
- private static final float THRESHOLD_GRAVITY = 3.2F;
- private static final int SLOP_TIME_MS = 1000; /*This decide after how much interval shake will detect */
- private static final int COUNT_RESET_TIME_MS = 3000;
- private Double mAccelCurrent, gForce = 0.00, mAccelLast = 0.00, mAccel = 0.00;
- private OnShakeListener mListener;
- private long mShakeTimestamp;
- private int mShakeCount;
Read more about the Shake Detector in Android visit Findnerd.