Seismic is an Android device shake detection library by Square. To use it just start listening to the shake events emitted by it.
@Override
protected void onCreate(Bundle savedInstanceState) {
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
sd = new ShakeDetector(() -> { /* react to detected shake */ });
}
@Override
protected void onResume() {
sd.start(sm);
}
@Override
protected void onPause() {
sd.stop();
}
To define the a different acceleration threshold use sd.setSensitivity(sensitivity)
with a sensitivity
of SENSITIVITY_LIGHT
, SENSITIVITY_MEDIUM
, SENSITIVITY_HARD
or any other reasonable integer value. The given default values range from 11 to 15.
compile 'com.squareup:seismic:1.0.2'