Sensing a DisturbanceAs The Busy Coder's Guide to Advanced Android Development explains:
The Shaker simply converts the three individual acceleration
components into a combined acceleration value (square rootof the sum of the squares), then compares that value to
Earth's gravity. If the ratio is higher than the suppliedthreshold, then we consider the device to be presently
shaking, and we call the shakingStarted() callback method ifthe device was not shaking before. Once shaking ends, and
time elapses, we call shakingStopped() on the callback object
and assume that the shake has ended. A more robustimplementation of Shaker would take into account the
possibility that the sensor will not be updated for a whileafter the shake ends, though in reality, normal human
movement will ensure that there are some sensor updates, sowe can find out when the shaking ends.
Step #2: Hook Into the Shaker
Given that you magically now have a Shaker object, we need to tie it into
the LunchList activity.
First, implement a Shaker.Callback object named onShake in LunchList:
private Shaker.Callback onShake=new Shaker.Callback() {
public void shakingStarted() {
}public void shakingStopped() {
}
};Right now, we do not do anything with the shake events, though we will
address that shortcoming in the next section.
Then, add a Shaker data member to LunchList, called shaker.